40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
'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>
|
||
);
|
||
}
|