forked from SelfPrivacy/selfprivacy.org.app
add validation
parent
65c6a0b870
commit
3a5353dbf4
|
@ -204,7 +204,6 @@
|
||||||
"6": "Delete the server and volume?",
|
"6": "Delete the server and volume?",
|
||||||
"7": "Yes",
|
"7": "Yes",
|
||||||
"8": "Remove task"
|
"8": "Remove task"
|
||||||
|
|
||||||
},
|
},
|
||||||
"timer": {
|
"timer": {
|
||||||
"sec": "{} sec"
|
"sec": "{} sec"
|
||||||
|
@ -216,10 +215,11 @@
|
||||||
"empty": "No jobs"
|
"empty": "No jobs"
|
||||||
},
|
},
|
||||||
"validations": {
|
"validations": {
|
||||||
"required": "required",
|
"required": "Required",
|
||||||
"invalid_format": "invalid format",
|
"invalid_format": "Invalid format",
|
||||||
"root_name": "User name cannot be 'root'",
|
"root_name": "User name cannot be 'root'",
|
||||||
"key_format": "invalid key format",
|
"key_format": "Invalid key format",
|
||||||
"length": "length is [] shoud be {}"
|
"length": "Length is [] shoud be {}",
|
||||||
|
"user_alredy_exist": "Already exists"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -216,9 +216,10 @@
|
||||||
},
|
},
|
||||||
"validations": {
|
"validations": {
|
||||||
"required": "обязательное поле",
|
"required": "обязательное поле",
|
||||||
"invalid_format": "неверный формат",
|
"invalid_format": "Неверный формат",
|
||||||
"root_name": "Имя пользователя не может быть'root'",
|
"root_name": "Имя пользователя не может быть'root'",
|
||||||
"key_format": "неверный формат",
|
"key_format": "Неверный формат",
|
||||||
"length": "Длина строки [] должна быть {}"
|
"length": "Длина строки [] должна быть {}",
|
||||||
|
"user_alredy_exist": "Имя уже используется"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,8 @@ import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
class UserFormCubit extends FormCubit {
|
class UserFormCubit extends FormCubit {
|
||||||
UserFormCubit({
|
UserFormCubit({
|
||||||
required this.usersCubit,
|
required this.jobsCubit,
|
||||||
|
required List<User> users,
|
||||||
User? user,
|
User? user,
|
||||||
}) {
|
}) {
|
||||||
var isEdit = user != null;
|
var isEdit = user != null;
|
||||||
|
@ -20,6 +21,10 @@ class UserFormCubit extends FormCubit {
|
||||||
login = FieldCubit(
|
login = FieldCubit(
|
||||||
initalValue: isEdit ? user!.login : '',
|
initalValue: isEdit ? user!.login : '',
|
||||||
validations: [
|
validations: [
|
||||||
|
ValidationModel(
|
||||||
|
(login) => users.any((user) => user.login == login),
|
||||||
|
'validations.user_alredy_exist'.tr(),
|
||||||
|
),
|
||||||
RequiredStringValidation('validations.required'.tr()),
|
RequiredStringValidation('validations.required'.tr()),
|
||||||
ValidationModel<String>(
|
ValidationModel<String>(
|
||||||
(s) => userRegExp.hasMatch(s), 'validations.invalid_format'.tr()),
|
(s) => userRegExp.hasMatch(s), 'validations.invalid_format'.tr()),
|
||||||
|
@ -44,7 +49,7 @@ class UserFormCubit extends FormCubit {
|
||||||
login: login.state.value,
|
login: login.state.value,
|
||||||
password: password.state.value,
|
password: password.state.value,
|
||||||
);
|
);
|
||||||
usersCubit.addJob(CreateUserJob(user: user));
|
jobsCubit.addJob(CreateUserJob(user: user));
|
||||||
}
|
}
|
||||||
|
|
||||||
late FieldCubit<String> login;
|
late FieldCubit<String> login;
|
||||||
|
@ -54,5 +59,5 @@ class UserFormCubit extends FormCubit {
|
||||||
password.externalSetValue(genPass());
|
password.externalSetValue(genPass());
|
||||||
}
|
}
|
||||||
|
|
||||||
late JobsCubit usersCubit;
|
final JobsCubit jobsCubit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,24 @@ class _NewUser extends StatelessWidget {
|
||||||
|
|
||||||
return BrandBottomSheet(
|
return BrandBottomSheet(
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) =>
|
create: (context) {
|
||||||
UserFormCubit(usersCubit: context.read<JobsCubit>()),
|
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,
|
||||||
|
);
|
||||||
|
},
|
||||||
child: Builder(builder: (context) {
|
child: Builder(builder: (context) {
|
||||||
var formCubitState = context.watch<UserFormCubit>().state;
|
var formCubitState = context.watch<UserFormCubit>().state;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/jobs/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||||
|
|
Loading…
Reference in New Issue