Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

146 řádky
3.6KB

  1. import { Box, Button, Stack, Typography } from "@mui/material";
  2. import { HasChildren } from "@types";
  3. import { reOrderSticker } from "api/season-ticket-contract";
  4. import { FormProvider, RHFTextField } from "components/hook-form";
  5. import { RHFUpload } from "components/hook-form/RHFUpload";
  6. import { useSeasonTicketContractContext } from "contexts/dashboard/SeasonTicketContractContext";
  7. import useAPICall from "hooks/useAPICall";
  8. import useDashboard from "hooks/useDashBoard";
  9. import useNavigateCustom from "hooks/useNavigateCustom";
  10. import useSnackbarCustom from "hooks/useSnackbarCustom";
  11. import { useUpload } from "hooks/useUpload";
  12. import { PageID, TabID } from "pages";
  13. import { useEffect, useState } from "react";
  14. import { useForm } from "react-hook-form";
  15. import { getPath } from "routes/path";
  16. type AreaBoxProps = {
  17. label: string;
  18. } & HasChildren;
  19. function AreaBox({ label, children }: AreaBoxProps) {
  20. return (
  21. <Box>
  22. <Typography variant="body2">{label}</Typography>
  23. {children}
  24. </Box>
  25. );
  26. }
  27. type FormProps = {
  28. upload1: File[];
  29. };
  30. export default function StickerReOrder() {
  31. const { setHeaderTitle, setTabs } = useDashboard(
  32. PageID.DASHBOARD_SEASON_TICKET_CONTRACT_STICKER_RE_ORDER,
  33. TabID.NONE
  34. );
  35. const form = useForm<FormProps>({
  36. defaultValues: {
  37. upload1: [],
  38. },
  39. });
  40. const { navigateWhenChanged, navigate } = useNavigateCustom();
  41. const { error } = useSnackbarCustom();
  42. const { selectedseasonTicketContract } = useSeasonTicketContractContext();
  43. const [done, setDone] = useState(false);
  44. const { callAPI: callReOrderSticker } = useAPICall({
  45. apiMethod: reOrderSticker,
  46. backDrop: true,
  47. onSuccess: () => {
  48. setDone(true);
  49. },
  50. onFailed: () => {
  51. error("依頼失敗しました");
  52. },
  53. });
  54. const handleSubmit = (data: FormProps) => {
  55. console.log(data);
  56. return;
  57. // if (selectedseasonTicketContract === null) return;
  58. // callReOrderSticker({
  59. // season_ticket_contract_record_no:
  60. // selectedseasonTicketContract.season_ticekt_contract_record_no ?? "",
  61. // });
  62. };
  63. useEffect(() => {
  64. setHeaderTitle("シール再発行依頼");
  65. setTabs(null);
  66. }, [setHeaderTitle, setTabs]);
  67. useEffect(() => {
  68. if (selectedseasonTicketContract === null) {
  69. navigateWhenChanged(
  70. getPath(PageID.DASHBOARD_SEASON_TICKET_CONTRACT_LIST)
  71. );
  72. }
  73. }, [selectedseasonTicketContract]);
  74. if (selectedseasonTicketContract === null) {
  75. return null;
  76. }
  77. if (done) {
  78. return (
  79. <Box sx={{ mt: 1 }}>
  80. <Stack spacing={2}>
  81. <Box>依頼しました</Box>
  82. <Box>
  83. <Button
  84. onClick={() => {
  85. navigate(-1);
  86. }}
  87. >
  88. 戻る
  89. </Button>
  90. </Box>
  91. </Stack>
  92. </Box>
  93. );
  94. }
  95. return (
  96. <FormProvider methods={form} onSubmit={form.handleSubmit(handleSubmit)}>
  97. <Box sx={{ mt: 1 }}>
  98. <Stack spacing={2}>
  99. <Box>
  100. <Button
  101. onClick={() => {
  102. navigate(-1);
  103. }}
  104. >
  105. 戻る
  106. </Button>
  107. </Box>
  108. <AreaBox label="申請理由">
  109. <RHFTextField
  110. name="reason"
  111. size="small"
  112. multiline
  113. minRows={3}
  114. maxRows={10}
  115. />
  116. </AreaBox>
  117. <AreaBox label="アップロード">
  118. <RHFUpload name="upload1" />
  119. </AreaBox>
  120. <Box>
  121. <Button variant="contained" type="submit">
  122. 確定
  123. </Button>
  124. </Box>
  125. </Stack>
  126. </Box>
  127. </FormProvider>
  128. );
  129. }