2021-01-06 17:35:57 +00:00
|
|
|
part of 'users.dart';
|
|
|
|
|
2022-05-30 13:49:42 +00:00
|
|
|
class NewUser extends StatelessWidget {
|
2022-06-05 22:40:34 +00:00
|
|
|
const NewUser({final 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
|
|
|
|
2021-06-20 21:08:52 +00:00
|
|
|
return BrandBottomSheet(
|
2021-01-14 18:45:10 +00:00
|
|
|
child: BlocProvider(
|
2022-06-05 22:40:34 +00:00
|
|
|
create: (final BuildContext context) {
|
|
|
|
final jobCubit = context.read<JobsCubit>();
|
|
|
|
final jobState = jobCubit.state;
|
|
|
|
final users = <User>[];
|
2021-07-29 09:34:26 +00:00
|
|
|
users.addAll(context.read<UsersCubit>().state.users);
|
|
|
|
if (jobState is JobsStateWithJobs) {
|
2022-08-24 05:35:49 +00:00
|
|
|
final jobs = jobState.clientJobList;
|
2022-06-05 22:40:34 +00:00
|
|
|
for (final job in jobs) {
|
2021-07-29 09:34:26 +00:00
|
|
|
if (job is CreateUserJob) {
|
|
|
|
users.add(job.user);
|
|
|
|
}
|
2022-05-24 18:55:39 +00:00
|
|
|
}
|
2021-07-29 09:34:26 +00:00
|
|
|
}
|
|
|
|
return UserFormCubit(
|
|
|
|
jobsCubit: jobCubit,
|
2022-05-04 16:58:47 +00:00
|
|
|
fieldFactory: FieldCubitFactory(context),
|
2021-07-29 09:34:26 +00:00
|
|
|
);
|
|
|
|
},
|
2022-06-05 22:40:34 +00:00
|
|
|
child: Builder(
|
|
|
|
builder: (final BuildContext context) {
|
|
|
|
final FormCubitState formCubitState =
|
|
|
|
context.watch<UserFormCubit>().state;
|
2021-01-14 18:45:10 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
return BlocListener<UserFormCubit, FormCubitState>(
|
|
|
|
listener:
|
|
|
|
(final BuildContext context, final FormCubitState state) {
|
|
|
|
if (state.isSubmitted) {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
BrandHeader(
|
|
|
|
title: 'users.new_user'.tr(),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 14),
|
|
|
|
Padding(
|
|
|
|
padding: paddingH15V0,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
IntrinsicHeight(
|
|
|
|
child: CubitFormTextField(
|
|
|
|
formFieldCubit: context.read<UserFormCubit>().login,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'users.login'.tr(),
|
|
|
|
suffixText: '@$domainName',
|
|
|
|
),
|
2021-06-20 21:08:52 +00:00
|
|
|
),
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
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),
|
|
|
|
child: IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
BrandIcons.refresh,
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
onPressed: context
|
|
|
|
.read<UserFormCubit>()
|
|
|
|
.genNewPassword,
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
|
|
|
),
|
2022-06-05 22:40:34 +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
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|