2023-11-16 17:09:22 +03:00

40 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import * as apiIus from '@/api/ius/query';
import { useFormStore } from '@/store/ius/form';
import { makeCreateUrl, type PageUrlParams } from '@/utils/url';
import { Button } from 'ui';
export function Buttons({ pageUrlParams }: { readonly pageUrlParams: PageUrlParams }) {
const { reset, setValidation, values } = useFormStore();
const createUrl = makeCreateUrl(pageUrlParams);
return (
<div className="grid grid-cols-1 gap-2 gap-x-4 md:grid-cols-3">
<Button
intent="outline-danger"
onClick={() => {
reset();
}}
>
Отмена
</Button>
<Button intent="secondary">Возврат на доработку</Button>
<Button
onClick={() => {
apiIus.validate({ createUrl, payload: values }).then((res) => {
if (typeof res !== 'boolean') {
Object.keys(res.errors).forEach((name) => {
const elementValidation = res?.errors?.[name];
if (elementValidation)
setValidation({ message: elementValidation[0] ?? '', name, valid: false });
});
}
});
}}
>
Сохранить
</Button>
</div>
);
}