2021-01-06 17:35:57 +00:00
|
|
|
part of 'users.dart';
|
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2023-02-24 16:45:32 +00:00
|
|
|
class NewUserPage extends StatelessWidget {
|
|
|
|
const NewUserPage({super.key});
|
2022-05-30 23:06:08 +00:00
|
|
|
|
2021-01-06 17:35:57 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final ServerInstallationState config =
|
|
|
|
context.watch<ServerInstallationCubit>().state;
|
2021-03-18 00:55:38 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final String domainName = UiHelpers.getDomainName(config);
|
2021-03-18 00:55:38 +00:00
|
|
|
|
2023-02-24 16:45:32 +00:00
|
|
|
return BlocProvider(
|
|
|
|
create: (final BuildContext context) {
|
|
|
|
final jobCubit = context.read<JobsCubit>();
|
|
|
|
final jobState = jobCubit.state;
|
|
|
|
final users = <User>[];
|
2024-02-09 15:01:05 +00:00
|
|
|
users.addAll(context.read<UsersBloc>().state.users);
|
2023-02-24 16:45:32 +00:00
|
|
|
if (jobState is JobsStateWithJobs) {
|
|
|
|
final jobs = jobState.clientJobList;
|
|
|
|
for (final job in jobs) {
|
|
|
|
if (job is CreateUserJob) {
|
|
|
|
users.add(job.user);
|
2022-05-24 18:55:39 +00:00
|
|
|
}
|
2021-07-29 09:34:26 +00:00
|
|
|
}
|
2023-02-24 16:45:32 +00:00
|
|
|
}
|
|
|
|
return UserFormCubit(
|
|
|
|
jobsCubit: jobCubit,
|
|
|
|
fieldFactory: FieldCubitFactory(context),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Builder(
|
|
|
|
builder: (final BuildContext context) {
|
|
|
|
final FormCubitState formCubitState =
|
|
|
|
context.watch<UserFormCubit>().state;
|
2021-01-14 18:45:10 +00:00
|
|
|
|
2023-02-24 16:45:32 +00:00
|
|
|
return BlocListener<UserFormCubit, FormCubitState>(
|
|
|
|
listener: (final BuildContext context, final FormCubitState state) {
|
|
|
|
if (state.isSubmitted) {
|
2024-04-02 15:11:29 +00:00
|
|
|
context.router.maybePop();
|
2023-02-24 16:45:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: BrandHeroScreen(
|
|
|
|
heroTitle: 'users.new_user'.tr(),
|
|
|
|
heroIcon: Icons.person_add_outlined,
|
|
|
|
children: [
|
|
|
|
if (formCubitState.isErrorShown)
|
|
|
|
Text(
|
|
|
|
'users.username_rule'.tr(),
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2023-02-24 16:45:32 +00:00
|
|
|
const SizedBox(width: 14),
|
|
|
|
IntrinsicHeight(
|
|
|
|
child: CubitFormTextField(
|
2023-08-11 02:21:45 +00:00
|
|
|
autofocus: true,
|
2023-02-24 16:45:32 +00:00
|
|
|
formFieldCubit: context.read<UserFormCubit>().login,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'users.login'.tr(),
|
|
|
|
suffixText: '@$domainName',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
CubitFormTextField(
|
|
|
|
formFieldCubit: context.read<UserFormCubit>().password,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
alignLabelWithHint: false,
|
|
|
|
labelText: 'basis.password'.tr(),
|
|
|
|
suffixIcon: Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8),
|
2023-12-28 13:19:16 +00:00
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.copy,
|
|
|
|
size: 24.0,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
final String currentPassword = context
|
|
|
|
.read<UserFormCubit>()
|
|
|
|
.password
|
|
|
|
.state
|
|
|
|
.value;
|
|
|
|
PlatformAdapter.setClipboard(currentPassword);
|
|
|
|
getIt<NavigationService>().showSnackBar(
|
|
|
|
'basis.copied_to_clipboard'.tr(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.refresh,
|
|
|
|
size: 24.0,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
onPressed:
|
|
|
|
context.read<UserFormCubit>().genNewPassword,
|
|
|
|
),
|
|
|
|
],
|
2023-02-24 16:45:32 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
2023-02-24 16:45:32 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
BrandButton.rised(
|
|
|
|
onPressed: formCubitState.isSubmitting
|
|
|
|
? null
|
|
|
|
: () => context.read<UserFormCubit>().trySubmit(),
|
|
|
|
text: 'basis.create'.tr(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 40),
|
|
|
|
Text('users.new_user_info_note'.tr()),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|