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-05-30 23:06:08 +00:00
|
|
|
const NewUser({Key? key}) : super(key: key);
|
|
|
|
|
2021-01-06 17:35:57 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-05-17 13:31:34 +00:00
|
|
|
var config = context.watch<ServerInstallationCubit>().state;
|
2021-03-18 00:55:38 +00:00
|
|
|
|
2021-03-26 13:38:39 +00:00
|
|
|
var 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(
|
2021-07-29 09:34:26 +00:00
|
|
|
create: (context) {
|
|
|
|
var jobCubit = context.read<JobsCubit>();
|
|
|
|
var jobState = jobCubit.state;
|
|
|
|
var users = <User>[];
|
|
|
|
users.addAll(context.read<UsersCubit>().state.users);
|
|
|
|
if (jobState is JobsStateWithJobs) {
|
|
|
|
var jobs = jobState.jobList;
|
2022-05-24 18:55:39 +00:00
|
|
|
for (var 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
|
|
|
);
|
|
|
|
},
|
2021-01-14 18:45:10 +00:00
|
|
|
child: Builder(builder: (context) {
|
2021-03-15 15:39:44 +00:00
|
|
|
var formCubitState = context.watch<UserFormCubit>().state;
|
2021-01-14 18:45:10 +00:00
|
|
|
|
|
|
|
return BlocListener<UserFormCubit, FormCubitState>(
|
|
|
|
listener: (context, state) {
|
|
|
|
if (state.isSubmitted) {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2021-06-20 21:08:52 +00:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
2021-01-14 18:45:10 +00:00
|
|
|
children: [
|
2021-03-18 00:55:38 +00:00
|
|
|
BrandHeader(
|
|
|
|
title: 'users.new_user'.tr(),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(width: 14),
|
2021-01-14 18:45:10 +00:00
|
|
|
Padding(
|
2021-05-25 21:53:54 +00:00
|
|
|
padding: paddingH15V0,
|
2021-01-14 18:45:10 +00:00
|
|
|
child: Column(
|
2021-06-20 21:08:52 +00:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
2021-01-14 18:45:10 +00:00
|
|
|
children: [
|
2021-06-20 21:08:52 +00:00
|
|
|
IntrinsicHeight(
|
|
|
|
child: CubitFormTextField(
|
|
|
|
formFieldCubit: context.read<UserFormCubit>().login,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'users.login'.tr(),
|
|
|
|
suffixText: '@$domainName',
|
|
|
|
),
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 20),
|
2021-01-14 18:45:10 +00:00
|
|
|
CubitFormTextField(
|
2021-03-15 15:39:44 +00:00
|
|
|
formFieldCubit: context.read<UserFormCubit>().password,
|
2021-01-14 18:45:10 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
alignLabelWithHint: false,
|
2021-03-18 00:55:38 +00:00
|
|
|
labelText: 'basis.password'.tr(),
|
2021-01-14 18:45:10 +00:00
|
|
|
suffixIcon: Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8),
|
|
|
|
child: IconButton(
|
2022-05-30 16:55:09 +00:00
|
|
|
icon: Icon(
|
2021-01-14 18:45:10 +00:00
|
|
|
BrandIcons.refresh,
|
2022-05-30 16:55:09 +00:00
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
2021-03-15 15:39:44 +00:00
|
|
|
onPressed:
|
|
|
|
context.read<UserFormCubit>().genNewPassword,
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 30),
|
2021-01-14 18:45:10 +00:00
|
|
|
BrandButton.rised(
|
2021-03-15 15:39:44 +00:00
|
|
|
onPressed: formCubitState.isSubmitting
|
2021-01-14 18:45:10 +00:00
|
|
|
? null
|
2021-03-15 15:39:44 +00:00
|
|
|
: () => context.read<UserFormCubit>().trySubmit(),
|
2021-05-25 21:53:54 +00:00
|
|
|
text: 'basis.create'.tr(),
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 40),
|
2021-03-18 00:55:38 +00:00
|
|
|
Text('users.new_user_info_note'.tr()),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 30),
|
2021-01-14 18:45:10 +00:00
|
|
|
],
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
2021-01-14 18:45:10 +00:00
|
|
|
),
|
|
|
|
],
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
2021-01-14 18:45:10 +00:00
|
|
|
);
|
|
|
|
}),
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|