refactor: modals refactored
This commit is contained in:
@ -4,23 +4,23 @@ import { Button, Flex, rem, TextInput } from "@mantine/core";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
|
||||
type Props = {
|
||||
onComplete: (value: string) => void;
|
||||
defaultValue?: string;
|
||||
};
|
||||
|
||||
type FormType = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
onChange: (value: FormType) => void;
|
||||
value?: FormType;
|
||||
};
|
||||
|
||||
const EnterNameModal = ({
|
||||
id,
|
||||
context,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const form = useForm<FormType>({
|
||||
initialValues: {
|
||||
name: innerProps.defaultValue ?? "",
|
||||
initialValues: innerProps.value || {
|
||||
name: "",
|
||||
},
|
||||
validate: {
|
||||
name: name => !name && "Введите название",
|
||||
@ -28,7 +28,7 @@ const EnterNameModal = ({
|
||||
});
|
||||
|
||||
const onSubmit = (values: FormType) => {
|
||||
innerProps.onComplete(values.name);
|
||||
innerProps.onChange(values);
|
||||
context.closeModal(id);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user