| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import type { CustomerEntity, CustomerUpsertInput } from '../services/api/customers'
- export type CustomerFormValues = {
- name: string
- namePronunciation: string
- phone: string
- email: string
- birthday: string
- expectContact: 'LINE' | 'PHONE' | 'EMAIL' | 'NONE'
- hairLength: 'SHORT' | 'MEDIUM' | 'LONG' | 'UNCONFIRM'
- hairTexture: 'UNCONFIRM' | 'THIN' | 'NORMAL' | 'HARD_CRUDE' | 'CURLY'
- notice: string
- allergy: string
- innerRemark: string
- followContent: string
- nextFollowDate: string
- recommendVisitDate: string
- firstSuggestHair: 'AUTO' | 'LONG' | 'MEDIUM' | 'SHORT'
- planDate: string
- visitPurpose: 'CUT_DYE' | 'CUT' | 'DYE' | 'CONSULT_SIM' | ''
- trouble: string
- consultContent: string
- expectLook: string
- }
- export function emptyCustomerForm(): CustomerFormValues {
- return {
- name: '',
- namePronunciation: '',
- phone: '',
- email: '',
- birthday: '',
- expectContact: 'NONE',
- hairLength: 'UNCONFIRM',
- hairTexture: 'UNCONFIRM',
- notice: '',
- allergy: '',
- innerRemark: '',
- followContent: '',
- nextFollowDate: '',
- recommendVisitDate: '',
- firstSuggestHair: 'AUTO',
- planDate: '',
- visitPurpose: '',
- trouble: '',
- consultContent: '',
- expectLook: '',
- }
- }
- export function customerToFormValues(customer: CustomerEntity): CustomerFormValues {
- return {
- name: customer.name || '',
- namePronunciation: customer.namePronunciation || '',
- phone: customer.phone || '',
- email: customer.email || '',
- birthday: customer.birthday || '',
- expectContact: customer.expectContact || 'NONE',
- hairLength: customer.hairLength || 'UNCONFIRM',
- hairTexture: customer.hairTexture || 'UNCONFIRM',
- notice: customer.notice || '',
- allergy: customer.allergy || '',
- innerRemark: customer.innerRemark || '',
- followContent: customer.followContent || '',
- nextFollowDate: customer.nextFollowDate || '',
- recommendVisitDate: customer.recommendVisitDate || '',
- firstSuggestHair: customer.firstSuggestHair || 'AUTO',
- planDate: customer.planDate || '',
- visitPurpose: customer.visitPurpose || '',
- trouble: customer.trouble || '',
- consultContent: customer.consultContent || '',
- expectLook: customer.expectLook || '',
- }
- }
- export function formValuesToPayload(values: CustomerFormValues, avatar?: string): CustomerUpsertInput {
- const pick = (v: string) => (v.trim() ? v.trim() : undefined)
- return {
- name: values.name.trim(),
- phone: values.phone.trim(),
- namePronunciation: pick(values.namePronunciation),
- email: pick(values.email),
- birthday: pick(values.birthday),
- avatar,
- expectContact: values.expectContact,
- hairLength: values.hairLength,
- hairTexture: values.hairTexture,
- notice: pick(values.notice),
- allergy: pick(values.allergy),
- innerRemark: pick(values.innerRemark),
- followContent: pick(values.followContent),
- nextFollowDate: pick(values.nextFollowDate),
- recommendVisitDate: pick(values.recommendVisitDate),
- firstSuggestHair: values.firstSuggestHair,
- planDate: pick(values.planDate),
- visitPurpose: values.visitPurpose || undefined,
- trouble: pick(values.trouble),
- consultContent: pick(values.consultContent),
- expectLook: pick(values.expectLook),
- }
- }
|