38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
|
|
import * as Yup from "yup";
|
|
import { KeyAndValue, objectToArray } from "../../utils/object/objectToArray";
|
|
import { Restaurant } from "../../types/item";
|
|
|
|
|
|
export const getInitialValues = (objectToEdit: Restaurant ): any => {
|
|
|
|
|
|
const slogan: KeyAndValue[] = objectToArray(objectToEdit?.slogan);
|
|
const contact_info: KeyAndValue[] = objectToArray(objectToEdit?.contact_info);
|
|
const categories = objectToEdit?.categories?.map((item:any)=>(item.id)) || null;
|
|
|
|
return {
|
|
id: objectToEdit?.id ?? null,
|
|
name: objectToEdit?.name ?? null,
|
|
images: objectToEdit?.images ?? null,
|
|
logo: objectToEdit?.logo ?? null,
|
|
|
|
address: objectToEdit?.address ?? null,
|
|
phone_number:contact_info?.[0]?.value ?? null,
|
|
email:contact_info?.[1]?.value ?? null,
|
|
categories:categories,
|
|
slogan: slogan ?? null,
|
|
video: objectToEdit?.video ?? null,
|
|
attributes: objectToEdit?.attributes ?? null,
|
|
};
|
|
};
|
|
|
|
export const getValidationSchema = (editMode: boolean = false): Yup.Schema<any> => {
|
|
// Validate input
|
|
return Yup.object().shape({
|
|
name: Yup.string().required('Required'),
|
|
|
|
});
|
|
};
|
|
|