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

OrganizationCard.js 14 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年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // material-ui
  2. import {
  3. Grid, Button, Checkbox, FormControlLabel, Typography
  4. } from '@mui/material';
  5. // import { FormControlLabel } from '@material-ui/core';
  6. import MainCard from "../../components/MainCard";
  7. import * as React from "react";
  8. import { useFormik } from 'formik';
  9. import * as yup from 'yup';
  10. import { useEffect, useState } from "react";
  11. import * as HttpUtils from '../../utils/HttpUtils';
  12. import * as UrlUtils from "../../utils/ApiPathConst";
  13. import * as FieldUtils from "../../utils/FieldUtils";
  14. import * as ComboData from "../../utils/ComboData";
  15. const LoadingComponent = Loadable(lazy(() => import('../extra-pages/LoadingComponent')));
  16. import Loadable from 'components/Loadable';
  17. import { lazy } from 'react';
  18. import { notifySaveSuccess } from 'utils/CommonFunction';
  19. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  20. const OrganizationCard = ({ userData, loadDataFun, id }) => {
  21. const [currentUserData, setCurrentUserData] = useState({});
  22. const [editMode, setEditMode] = useState(false);
  23. const [createMode, setCreateMode] = useState(false);
  24. const [onReady, setOnReady] = useState(false);
  25. useEffect(() => {
  26. //if state data are ready and assign to different field
  27. // console.log(currentApplicationDetailData)
  28. if (Object.keys(currentUserData).length > 0) {
  29. setOnReady(true);
  30. }
  31. }, [currentUserData]);
  32. const formik = useFormik({
  33. enableReinitialize: true,
  34. initialValues: currentUserData,
  35. validationSchema: yup.object().shape({
  36. enCompanyName: yup.string().max(255).required('請輸入英文名稱'),
  37. chCompanyName: yup.string().max(255, '請輸入中文名稱').nullable(),
  38. addressLine1: yup.string().max(255).required('請輸入第一行地址'),
  39. addressLine2: yup.string().max(255, "length must <= 255"),
  40. addressLine3: yup.string().max(255, "length must <= 255"),
  41. fax_countryCode: yup.string().min(3, '請輸入國際區號').nullable(),
  42. tel_countryCode: yup.string().min(3, '請輸入國際區號'),
  43. phoneNumber: yup.string().min(8, '請輸入有效聯絡電話').required('請輸入聯絡電話'),
  44. faxNumber: yup.string().min(8, '請輸入8位數字').nullable(),
  45. brExpiryDate: yup.string().min(8).required('請輸入商業登記證有效日期'),
  46. brNo: yup.string().min(8, '請輸入有效商業登記證號碼').max(8, '請輸入有效商業登記證號碼').required('請輸入商業登記證號碼'),
  47. }),
  48. onSubmit: vaule => {
  49. console.log(vaule)
  50. HttpUtils.post({
  51. url: UrlUtils.POST_ORG_SAVE_PATH,
  52. params: {
  53. id: id > 0 ? id : null,
  54. enCompanyName: vaule.enCompanyName,
  55. chCompanyName: vaule.chCompanyName,
  56. brNo: vaule.brNo,
  57. brExpiryDate: vaule.brExpiryDate,
  58. enCompanyNameTemp: vaule.enCompanyNameTemp,
  59. chCompanyNameTemp: vaule.chCompanyNameTemp,
  60. brExpiryDateTemp: vaule.brExpiryDateTemp,
  61. contactPerson: vaule.contactPerson,
  62. contactTel: {
  63. countryCode: vaule.tel_countryCode,
  64. phoneNumber: vaule.phoneNumber
  65. },
  66. faxNo: {
  67. countryCode: vaule.fax_countryCode,
  68. faxNumber: vaule.faxNumber
  69. },
  70. addressTemp: {
  71. country: vaule.country,
  72. district: vaule.district,
  73. addressLine1: vaule.addressLine1,
  74. addressLine2: vaule.addressLine2,
  75. addressLine3: vaule.addressLine3,
  76. },
  77. creditor: vaule.creditor,
  78. },
  79. onSuccess: function () {
  80. notifySaveSuccess()
  81. loadDataFun();
  82. setEditMode(false);
  83. }
  84. });
  85. }
  86. });
  87. useEffect(() => {
  88. if (Object.keys(userData).length > 0) {
  89. setCreateMode(id <= 0);
  90. setEditMode(id <= 0);
  91. setCurrentUserData(userData);
  92. }
  93. }, [userData]);
  94. // useEffect(() => {
  95. // if (Object.keys(userData).length > 0) {
  96. // if(userData.creditor === undefined||userData.creditor === null){
  97. // userData.creditor = false
  98. // }
  99. // setCurrentUserData(userData);
  100. // }
  101. // }, []);
  102. const onEditClick = () => {
  103. setEditMode(true);
  104. };
  105. return (
  106. <MainCard elevation={0}
  107. border={false}
  108. content={false}
  109. >
  110. <form onSubmit={formik.handleSubmit} style={{ padding: 24 }}>
  111. {/*top*/}
  112. <Grid item s={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  113. <Grid container maxWidth justifyContent="flex-start">
  114. {editMode ?
  115. <>
  116. {createMode ?
  117. <>
  118. <Grid item sx={{ ml: 0, mr: 3 }}>
  119. <Button
  120. size="large"
  121. variant="contained"
  122. type="submit"
  123. sx={{
  124. textTransform: 'capitalize',
  125. alignItems: 'end'
  126. }}
  127. >
  128. Create
  129. </Button>
  130. </Grid>
  131. </> :
  132. <>
  133. <Grid item sx={{ ml: 0, mr: 3 }}>
  134. <Button
  135. size="large"
  136. variant="contained"
  137. onClick={loadDataFun}
  138. sx={{
  139. textTransform: 'capitalize',
  140. alignItems: 'end'
  141. }}
  142. >
  143. Reset & Back
  144. </Button>
  145. </Grid>
  146. <Grid item sx={{ ml: 3, mr: 3 }}>
  147. <Button
  148. size="large"
  149. variant="contained"
  150. type="submit"
  151. color="success"
  152. sx={{
  153. textTransform: 'capitalize',
  154. alignItems: 'end'
  155. }}
  156. >
  157. Save
  158. </Button>
  159. </Grid>
  160. </>
  161. }
  162. </>
  163. :
  164. <>
  165. <Grid item sx={{ ml: 0, mr: 3 }}>
  166. <Button
  167. size="large"
  168. variant="contained"
  169. sx={{
  170. textTransform: 'capitalize',
  171. alignItems: 'end'
  172. }}
  173. onClick={onEditClick}
  174. >
  175. Edit
  176. </Button>
  177. </Grid>
  178. </>
  179. }
  180. </Grid>
  181. </Grid>
  182. {/*top*/}
  183. {!onReady ?
  184. <LoadingComponent />
  185. :
  186. <Grid container spacing={1}>
  187. <Grid item xs={12}>
  188. <Typography variant="h5" sx={{mb: 2, mr: 3, borderBottom: "1px solid black" }}>
  189. Organization Details
  190. </Typography>
  191. </Grid>
  192. <Grid item lg={4} >
  193. {FieldUtils.getTextField({
  194. label: FieldUtils.notNullFieldLabel("BR No.:"),
  195. valueName: "brNo",
  196. disabled: (!editMode && !createMode),
  197. form: formik
  198. })}
  199. </Grid>
  200. <Grid item lg={4} >
  201. <FormControlLabel
  202. control={<Checkbox checked={formik.values.creditor} />}
  203. label="is Creditor"
  204. name="creditor"
  205. onChange={() => {
  206. formik.setFieldValue("creditor", !formik.values.creditor);
  207. }}
  208. disabled={!editMode && !createMode}
  209. />
  210. </Grid>
  211. <Grid item lg={4} ></Grid>
  212. <Grid item lg={4} >
  213. {FieldUtils.getTextField({
  214. label: FieldUtils.notNullFieldLabel("Name (Eng):"),
  215. valueName: "enCompanyName",
  216. disabled: (!editMode && !createMode),
  217. form: formik
  218. })}
  219. </Grid>
  220. <Grid item lg={4} >
  221. {FieldUtils.getTextField({
  222. label: "Name (Ch):",
  223. valueName: "chCompanyName",
  224. disabled: (!editMode && !createMode),
  225. form: formik
  226. })}
  227. </Grid>
  228. <Grid item lg={4} >
  229. {FieldUtils.getDateField({
  230. label: FieldUtils.notNullFieldLabel("Expiry Date:"),
  231. valueName: "brExpiryDate",
  232. disabled: (!editMode && !createMode),
  233. form: formik
  234. })}
  235. </Grid>
  236. <Grid item lg={4} >
  237. {FieldUtils.getTextField({
  238. label: FieldUtils.notNullFieldLabel("Contact Person:"),
  239. valueName: "contactPerson",
  240. disabled: (!editMode && !createMode),
  241. form: formik
  242. })}
  243. </Grid>
  244. <Grid item lg={4} >
  245. {FieldUtils.getPhoneField({
  246. label: FieldUtils.notNullFieldLabel("Contact Tel:"),
  247. valueName: {
  248. code: "tel_countryCode",
  249. num: "phoneNumber"
  250. },
  251. disabled: (!editMode && !createMode),
  252. form: formik
  253. })}
  254. </Grid>
  255. <Grid item lg={4} >
  256. {FieldUtils.getPhoneField({
  257. label: "Fax No:",
  258. valueName: {
  259. code: "fax_countryCode",
  260. num: "faxNumber"
  261. },
  262. disabled: (!editMode && !createMode),
  263. form: formik
  264. })}
  265. </Grid>
  266. <Grid item lg={4} >
  267. {FieldUtils.getComboField({
  268. label: FieldUtils.notNullFieldLabel("Country:"),
  269. valueName: "country",
  270. disabled: (!editMode && !createMode),
  271. dataList: ComboData.country,
  272. form: formik
  273. })}
  274. </Grid>
  275. <Grid item lg={4} >
  276. {FieldUtils.getComboField({
  277. label: FieldUtils.notNullFieldLabel("District:"),
  278. valueName: "district",
  279. disabled: (!editMode && !createMode),
  280. dataList: ComboData.district,
  281. form: formik
  282. })}
  283. </Grid>
  284. <Grid item lg={4} >
  285. {FieldUtils.getAddressField({
  286. label: FieldUtils.notNullFieldLabel("Address:"),
  287. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  288. disabled: (!editMode && !createMode),
  289. form: formik
  290. })}
  291. </Grid>
  292. <Grid item lg={12} ></Grid>
  293. </Grid>
  294. }
  295. </form>
  296. </MainCard>
  297. );
  298. };
  299. export default OrganizationCard;