customerForm.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import type { CustomerEntity, CustomerUpsertInput } from '../services/api/customers'
  2. export type CustomerFormValues = {
  3. name: string
  4. namePronunciation: string
  5. phone: string
  6. email: string
  7. birthday: string
  8. expectContact: 'LINE' | 'PHONE' | 'EMAIL' | 'NONE'
  9. hairLength: 'SHORT' | 'MEDIUM' | 'LONG' | 'UNCONFIRM'
  10. hairTexture: 'UNCONFIRM' | 'THIN' | 'NORMAL' | 'HARD_CRUDE' | 'CURLY'
  11. notice: string
  12. allergy: string
  13. innerRemark: string
  14. followContent: string
  15. nextFollowDate: string
  16. recommendVisitDate: string
  17. firstSuggestHair: 'AUTO' | 'LONG' | 'MEDIUM' | 'SHORT'
  18. planDate: string
  19. visitPurpose: 'CUT_DYE' | 'CUT' | 'DYE' | 'CONSULT_SIM' | ''
  20. trouble: string
  21. consultContent: string
  22. expectLook: string
  23. }
  24. export function emptyCustomerForm(): CustomerFormValues {
  25. return {
  26. name: '',
  27. namePronunciation: '',
  28. phone: '',
  29. email: '',
  30. birthday: '',
  31. expectContact: 'NONE',
  32. hairLength: 'UNCONFIRM',
  33. hairTexture: 'UNCONFIRM',
  34. notice: '',
  35. allergy: '',
  36. innerRemark: '',
  37. followContent: '',
  38. nextFollowDate: '',
  39. recommendVisitDate: '',
  40. firstSuggestHair: 'AUTO',
  41. planDate: '',
  42. visitPurpose: '',
  43. trouble: '',
  44. consultContent: '',
  45. expectLook: '',
  46. }
  47. }
  48. export function customerToFormValues(customer: CustomerEntity): CustomerFormValues {
  49. return {
  50. name: customer.name || '',
  51. namePronunciation: customer.namePronunciation || '',
  52. phone: customer.phone || '',
  53. email: customer.email || '',
  54. birthday: customer.birthday || '',
  55. expectContact: customer.expectContact || 'NONE',
  56. hairLength: customer.hairLength || 'UNCONFIRM',
  57. hairTexture: customer.hairTexture || 'UNCONFIRM',
  58. notice: customer.notice || '',
  59. allergy: customer.allergy || '',
  60. innerRemark: customer.innerRemark || '',
  61. followContent: customer.followContent || '',
  62. nextFollowDate: customer.nextFollowDate || '',
  63. recommendVisitDate: customer.recommendVisitDate || '',
  64. firstSuggestHair: customer.firstSuggestHair || 'AUTO',
  65. planDate: customer.planDate || '',
  66. visitPurpose: customer.visitPurpose || '',
  67. trouble: customer.trouble || '',
  68. consultContent: customer.consultContent || '',
  69. expectLook: customer.expectLook || '',
  70. }
  71. }
  72. export function formValuesToPayload(values: CustomerFormValues, avatar?: string): CustomerUpsertInput {
  73. const pick = (v: string) => (v.trim() ? v.trim() : undefined)
  74. return {
  75. name: values.name.trim(),
  76. phone: values.phone.trim(),
  77. namePronunciation: pick(values.namePronunciation),
  78. email: pick(values.email),
  79. birthday: pick(values.birthday),
  80. avatar,
  81. expectContact: values.expectContact,
  82. hairLength: values.hairLength,
  83. hairTexture: values.hairTexture,
  84. notice: pick(values.notice),
  85. allergy: pick(values.allergy),
  86. innerRemark: pick(values.innerRemark),
  87. firstSuggestHair: values.firstSuggestHair,
  88. planDate: pick(values.planDate),
  89. visitPurpose: values.visitPurpose || undefined,
  90. trouble: pick(values.trouble),
  91. consultContent: pick(values.consultContent),
  92. expectLook: pick(values.expectLook),
  93. }
  94. }