選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OrganizationCard.js 11 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // material-ui
  2. import {
  3. Grid, Typography, Button
  4. } from '@mui/material';
  5. import MainCard from "../../components/MainCard";
  6. import * as React from "react";
  7. import { useFormik } from 'formik';
  8. import * as yup from 'yup';
  9. import { useEffect, useState } from "react";
  10. import * as HttpUtils from '../../utils/HttpUtils';
  11. import * as UrlUtils from "../../utils/ApiPathConst";
  12. import * as FieldUtils from "../../utils/FieldUtils";
  13. import * as ComboData from "../../utils/ComboData";
  14. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  15. const OrganizationCard = ({ userData, loadDataFun, id }) => {
  16. const [currentUserData, setCurrentUserData] = useState(userData);
  17. const [editMode, setEditMode] = useState(false);
  18. const [createMode, setCreateMode] = useState(false);
  19. const formik = useFormik({
  20. enableReinitialize: true,
  21. initialValues: currentUserData,
  22. validationSchema: yup.object().shape({
  23. enCompanyName: yup.string().max(255).required('請輸入英文名稱'),
  24. chCompanyName: yup.string().max(255).required('請輸入中文姓名'),
  25. addressLine1: yup.string().max(255).required('請輸入第一行地址'),
  26. addressLine2: yup.string().max(255, "length must <= 255"),
  27. addressLine3: yup.string().max(255, "length must <= 255"),
  28. fax_countryCode: yup.string().min(3).required('請輸入國際區號'),
  29. tel_countryCode: yup.string().min(3).required('請輸入國際區號'),
  30. phoneNumber: yup.string().min(8).required('請輸入聯絡電話'),
  31. faxNumber: yup.string().min(8).required('請輸入8位數字'),
  32. brExpiryDate: yup.string().min(8).required('請輸入商業登記證有效日期'),
  33. brNo: yup.string().min(8).required('請輸入商業登記證號碼'),
  34. }),
  35. onSubmit: vaule => {
  36. console.log(vaule)
  37. HttpUtils.post({
  38. url: UrlUtils.POST_ORG_SAVE_PATH,
  39. params: {
  40. id: id > 0 ? id : null,
  41. enCompanyName: vaule.enCompanyName,
  42. chCompanyName: vaule.chCompanyName,
  43. brNo: vaule.brNo,
  44. brExpiryDate: vaule.brExpiryDate,
  45. enCompanyNameTemp: vaule.enCompanyNameTemp,
  46. chCompanyNameTemp: vaule.chCompanyNameTemp,
  47. brExpiryDateTemp: vaule.brExpiryDateTemp,
  48. contactPerson: vaule.contactPerson,
  49. contactTel: {
  50. countryCode: vaule.tel_countryCode,
  51. phoneNumber: vaule.phoneNumber
  52. },
  53. faxNo: {
  54. countryCode: vaule.fax_countryCode,
  55. faxNumber: vaule.faxNumber
  56. },
  57. addressTemp: {
  58. country: vaule.country,
  59. district: vaule.district,
  60. addressLine1: vaule.addressLine1,
  61. addressLine2: vaule.addressLine2,
  62. addressLine3: vaule.addressLine3,
  63. }
  64. },
  65. onSuccess: function () {
  66. loadDataFun();
  67. setEditMode(false);
  68. }
  69. });
  70. }
  71. });
  72. useEffect(() => {
  73. setCreateMode(id <= 0);
  74. setEditMode(id <= 0);
  75. setCurrentUserData(userData);
  76. }, [userData]);
  77. const onEditClick = () => {
  78. setEditMode(true);
  79. };
  80. return (
  81. <MainCard elevation={0}
  82. border={false}
  83. content={false}
  84. >
  85. <Typography variant="h5" sx={{ mt: 3, ml: 3, mb: 1 }}>
  86. Information
  87. </Typography>
  88. <form onSubmit={formik.handleSubmit}>
  89. {/*top*/}
  90. <Grid item s={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  91. <Grid container maxWidth justifyContent="flex-start">
  92. {editMode ?
  93. <>
  94. {createMode ?
  95. <>
  96. <Grid item sx={{ ml: 3, mr: 3 }}>
  97. <Button
  98. size="large"
  99. variant="contained"
  100. type="submit"
  101. sx={{
  102. textTransform: 'capitalize',
  103. alignItems: 'end'
  104. }}
  105. >
  106. Create
  107. </Button>
  108. </Grid>
  109. </> :
  110. <>
  111. <Grid item sx={{ ml: 3, mr: 3 }}>
  112. <Button
  113. size="large"
  114. variant="contained"
  115. onClick={loadDataFun}
  116. sx={{
  117. textTransform: 'capitalize',
  118. alignItems: 'end'
  119. }}
  120. >
  121. Reset & Back
  122. </Button>
  123. </Grid>
  124. <Grid item sx={{ ml: 3, mr: 3 }}>
  125. <Button
  126. size="large"
  127. variant="contained"
  128. type="submit"
  129. color="success"
  130. sx={{
  131. textTransform: 'capitalize',
  132. alignItems: 'end'
  133. }}
  134. >
  135. Save
  136. </Button>
  137. </Grid>
  138. </>
  139. }
  140. </>
  141. :
  142. <>
  143. <Grid item sx={{ ml: 3, mr: 3 }}>
  144. <Button
  145. size="large"
  146. variant="contained"
  147. sx={{
  148. textTransform: 'capitalize',
  149. alignItems: 'end'
  150. }}
  151. onClick={onEditClick}
  152. >
  153. Edit
  154. </Button>
  155. </Grid>
  156. </>
  157. }
  158. </Grid>
  159. </Grid>
  160. {/*top*/}
  161. <Grid container spacing={1}>
  162. {FieldUtils.getTextField({
  163. label: "BR No.:",
  164. valueName: "brNo",
  165. disabled: (!editMode && !createMode),
  166. form: formik
  167. })}
  168. <Grid item lg={8} ></Grid>
  169. {FieldUtils.getTextField({
  170. label: "Name (Eng):",
  171. valueName: "enCompanyName",
  172. disabled: (!editMode && !createMode),
  173. form: formik
  174. })}
  175. {FieldUtils.getTextField({
  176. label: "Name (Ch):",
  177. valueName: "chCompanyName",
  178. disabled: (!editMode && !createMode),
  179. form: formik
  180. })}
  181. {FieldUtils.getDateField({
  182. label: "Expiry Date:",
  183. valueName: "brExpiryDate",
  184. disabled: (!editMode && !createMode),
  185. form: formik
  186. })}
  187. {FieldUtils.getTextField({
  188. label: "Contact Person:",
  189. valueName: "contactPerson",
  190. disabled: (!editMode && !createMode),
  191. form: formik
  192. })}
  193. {FieldUtils.getPhoneField({
  194. label: "Contact Tel:",
  195. valueName: {
  196. code: "tel_countryCode",
  197. num: "phoneNumber"
  198. },
  199. disabled: (!editMode && !createMode),
  200. form: formik
  201. })}
  202. {FieldUtils.getPhoneField({
  203. label: "Fax No:",
  204. valueName: {
  205. code: "fax_countryCode",
  206. num: "faxNumber"
  207. },
  208. disabled: (!editMode && !createMode),
  209. form: formik
  210. })}
  211. {FieldUtils.getComboField({
  212. label: "Country:",
  213. valueName: "country",
  214. disabled: (!editMode && !createMode),
  215. dataList: ComboData.country,
  216. form: formik
  217. })}
  218. {FieldUtils.getComboField({
  219. label: "District:",
  220. valueName: "district",
  221. disabled: (!editMode && !createMode),
  222. dataList: ComboData.district,
  223. form: formik
  224. })}
  225. {FieldUtils.getAddressField({
  226. label: "Address:",
  227. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  228. disabled: (!editMode && !createMode),
  229. form: formik
  230. })}
  231. <Grid item lg={12} ></Grid>
  232. </Grid>
  233. </form>
  234. </MainCard>
  235. );
  236. };
  237. export default OrganizationCard;