selfprivacy.org.app/lib/ui/pages/users/new_user.dart

101 lines
3.5 KiB
Dart
Raw Normal View History

2021-01-06 17:35:57 +00:00
part of 'users.dart';
2021-01-14 18:45:10 +00:00
class _NewUser extends StatelessWidget {
2021-01-06 17:35:57 +00:00
@override
Widget build(BuildContext context) {
2021-03-18 00:55:38 +00:00
var config = context.watch<AppConfigCubit>().state;
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;
jobs.forEach((job) {
if (job is CreateUserJob) {
users.add(job.user);
}
});
}
return UserFormCubit(
jobsCubit: jobCubit,
users: users,
);
},
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(),
),
2021-01-14 18:45:10 +00:00
SizedBox(width: 14),
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
),
),
SizedBox(height: 20),
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(
icon: Icon(
BrandIcons.refresh,
color: BrandColors.blue,
),
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
),
),
),
2021-01-14 18:45:10 +00:00
SizedBox(height: 30),
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
),
SizedBox(height: 40),
2021-03-18 00:55:38 +00:00
Text('users.new_user_info_note'.tr()),
2021-01-14 18:45:10 +00:00
SizedBox(height: 30),
],
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
),
);
}
}