You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
6.7KB

  1. import { Box, Button, Stack, Typography } from "@mui/material";
  2. import { HasChildren } from "@types";
  3. import {
  4. getSeasonTicketContractTerminateOptions,
  5. orderSeasonTicketContractTerminate,
  6. reOrderSticker,
  7. } from "api/season-ticket-contract";
  8. import RequireChip from "components/chip/RequireChip";
  9. import {
  10. FormProvider,
  11. RHFCheckbox,
  12. RHFMultiCheckbox,
  13. RHFSelect,
  14. RHFTextField,
  15. } from "components/hook-form";
  16. import RHFDatePicker from "components/hook-form/RHFDatePicker";
  17. import { SelectOptionProps } from "components/hook-form/RHFSelect";
  18. import StackRow from "components/stack/StackRow";
  19. import { useSeasonTicketContractContext } from "contexts/dashboard/SeasonTicketContractContext";
  20. import useAPICall from "hooks/useAPICall";
  21. import useDashboard from "hooks/useDashBoard";
  22. import useNavigateCustom from "hooks/useNavigateCustom";
  23. import useSnackbarCustom from "hooks/useSnackbarCustom";
  24. import { PageID, TabID } from "pages";
  25. import { useEffect, useMemo, useState } from "react";
  26. import { useForm } from "react-hook-form";
  27. import { getPath } from "routes/path";
  28. type AreaBoxProps = {
  29. label: string;
  30. require?: boolean;
  31. } & HasChildren;
  32. function AreaBox({ label, children, require }: AreaBoxProps) {
  33. return (
  34. <Box>
  35. <StackRow>
  36. <Typography variant="subtitle1">〇{label}</Typography>
  37. <RequireChip require={require ?? false} />
  38. </StackRow>
  39. {children}
  40. </Box>
  41. );
  42. }
  43. type FormProps = {
  44. date: string;
  45. reason: string[];
  46. other_reason: string;
  47. opinion: string;
  48. memo: string;
  49. };
  50. export default function TerminateOrder() {
  51. const { setHeaderTitle, setTabs } = useDashboard(
  52. PageID.DASHBOARD_SEASON_TICKET_CONTRACT_TERMINATE_ORDER,
  53. TabID.NONE
  54. );
  55. const form = useForm<FormProps>({
  56. defaultValues: {
  57. date: "",
  58. reason: [],
  59. other_reason: "",
  60. opinion: "",
  61. memo: "",
  62. },
  63. });
  64. const { navigateWhenChanged, navigate } = useNavigateCustom();
  65. const { error } = useSnackbarCustom();
  66. const { selectedseasonTicketContract } = useSeasonTicketContractContext();
  67. const [monthes, setMonthes] = useState<string[]>([]);
  68. const monthOptions: SelectOptionProps[] = useMemo(() => {
  69. return monthes.map((ele) => ({
  70. value: ele,
  71. label: ele,
  72. }));
  73. }, [monthes]);
  74. const [done, setDone] = useState(false);
  75. const { callAPI: callOrderSeasonTicketContractTerminate } = useAPICall({
  76. apiMethod: orderSeasonTicketContractTerminate,
  77. backDrop: true,
  78. onSuccess: () => {
  79. setDone(true);
  80. },
  81. onFailed: () => {
  82. error("依頼失敗しました");
  83. },
  84. });
  85. const { callAPI: callGetSeasonTicketContractTerminateOptions } = useAPICall({
  86. apiMethod: getSeasonTicketContractTerminateOptions,
  87. backDrop: true,
  88. onSuccess: ({ data }) => {
  89. setMonthes(data.monthes);
  90. },
  91. });
  92. const handleSubmit = (data: FormProps) => {
  93. console.log(data);
  94. if (selectedseasonTicketContract === null) return;
  95. callOrderSeasonTicketContractTerminate({
  96. ...data,
  97. season_ticket_contract_record_no:
  98. selectedseasonTicketContract.season_ticekt_contract_record_no ?? "",
  99. reason: data.reason.join(","),
  100. });
  101. };
  102. const reasons = useMemo(() => {
  103. return [
  104. "転居/転勤のため",
  105. "就職/進学/卒業のため",
  106. "料金が高いため",
  107. "支払いが困難なため",
  108. "車/バイク/自転車に乗らなくなったため",
  109. "より良い駐車場/駐輪場が見つかったため",
  110. "駐車場/駐輪場に不満があるため(詳細)",
  111. "その他(詳細)",
  112. ].map((ele, index) => ({
  113. label: String(index + 1) + "." + String(ele),
  114. value: ele,
  115. }));
  116. }, []);
  117. useEffect(() => {
  118. setHeaderTitle("解約依頼申請");
  119. setTabs(null);
  120. }, [setHeaderTitle, setTabs]);
  121. useEffect(() => {
  122. if (selectedseasonTicketContract === null) {
  123. navigateWhenChanged(
  124. getPath(PageID.DASHBOARD_SEASON_TICKET_CONTRACT_LIST)
  125. );
  126. return;
  127. }
  128. callGetSeasonTicketContractTerminateOptions({
  129. season_ticket_contract_record_no:
  130. selectedseasonTicketContract.season_ticekt_contract_record_no ?? "",
  131. });
  132. }, [selectedseasonTicketContract]);
  133. if (selectedseasonTicketContract === null) {
  134. return null;
  135. }
  136. if (done) {
  137. return (
  138. <Box sx={{ mt: 1 }}>
  139. <Stack spacing={2}>
  140. <Box>依頼しました</Box>
  141. <Box>
  142. <Button
  143. onClick={() => {
  144. navigate(-1);
  145. }}
  146. >
  147. 戻る
  148. </Button>
  149. </Box>
  150. </Stack>
  151. </Box>
  152. );
  153. }
  154. return (
  155. <FormProvider methods={form} onSubmit={form.handleSubmit(handleSubmit)}>
  156. <Box sx={{ mt: 1 }}>
  157. <Stack spacing={2}>
  158. <Box>
  159. <Button
  160. onClick={() => {
  161. navigate(-1);
  162. }}
  163. >
  164. 戻る
  165. </Button>
  166. </Box>
  167. <AreaBox label="解約希望日" require>
  168. <RHFSelect name="date" size="small" options={monthOptions} />
  169. </AreaBox>
  170. <AreaBox label="解約理由(複数選択可)" require>
  171. <Typography variant="body2">
  172. 解約の理由についてお聞かせ下さい(複数選択可)
  173. </Typography>
  174. <RHFMultiCheckbox name="reason" options={reasons} />
  175. </AreaBox>
  176. <AreaBox label="解約理由詳細">
  177. <Typography variant="body2">
  178. 前質問 7・8を選択された方 詳細を詳しくお聞かせください。
  179. </Typography>
  180. <RHFTextField
  181. name="reason_other"
  182. size="small"
  183. multiline
  184. minRows={3}
  185. maxRows={10}
  186. />
  187. </AreaBox>
  188. <AreaBox label="ご意見">
  189. <Typography variant="body2">
  190. 今後の管理運営に生かすため、ご意見がありましたらご記入ください。
  191. </Typography>
  192. <RHFTextField
  193. name="opinion"
  194. size="small"
  195. multiline
  196. minRows={3}
  197. maxRows={10}
  198. />
  199. </AreaBox>
  200. <AreaBox label="備考">
  201. <Typography variant="body2">
  202. ご不明点等がございましたらご入力ください。お電話またはメールにて回答させていただきます。
  203. </Typography>
  204. <RHFTextField
  205. name="memo"
  206. size="small"
  207. multiline
  208. minRows={3}
  209. maxRows={10}
  210. />
  211. </AreaBox>
  212. <Box>
  213. <Button variant="contained" type="submit">
  214. 確定
  215. </Button>
  216. </Box>
  217. </Stack>
  218. </Box>
  219. </FormProvider>
  220. );
  221. }