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.
 
 

513 lines
26 KiB

  1. // material-ui
  2. import {
  3. Grid, Button, Typography
  4. } from '@mui/material';
  5. import MainCard from "../../../components/MainCard";
  6. import * as React from "react";
  7. import { useEffect, useState } from "react";
  8. import * as yup from 'yup';
  9. import { useFormik } from 'formik';
  10. import * as FieldUtils from "../../../utils/FieldUtils";
  11. import * as HttpUtils from '../../../utils/HttpUtils';
  12. import * as UrlUtils from "../../../utils/ApiPathConst";
  13. import * as ComboData from "../../../utils/ComboData";
  14. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  15. import Loadable from 'components/Loadable';
  16. import { lazy } from 'react';
  17. import { notifyActiveSuccess, notifyLockSuccess, notifySaveSuccess, notifyVerifySuccess } from 'utils/CommonFunction';
  18. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
  20. const [currentUserData, setCurrentUserData] = useState(formData);
  21. const [editMode, setEditMode] = useState(false);
  22. const [locked, setLocked] = useState(false);
  23. const [onReady, setOnReady] = useState(false);
  24. useEffect(() => {
  25. //if state data are ready and assign to different field
  26. // console.log(currentApplicationDetailData)
  27. if (Object.keys(currentUserData).length > 0) {
  28. setOnReady(true);
  29. }
  30. }, [currentUserData]);
  31. const formik = useFormik({
  32. enableReinitialize: true,
  33. initialValues: currentUserData,
  34. validationSchema: yup.object().shape({
  35. enName: yup.string().max(255).required('請輸入英文姓名'),
  36. chName: yup.string().max(255).required('請輸入中文姓名'),
  37. addressLine1: yup.string().max(255).required('請輸入第一行地址'),
  38. addressLine2: yup.string().max(255).nullable(),
  39. addressLine3: yup.string().max(255).nullable(),
  40. emailAddress: yup.string().email('請輸入電郵格式').max(255).required('請輸入電郵'),
  41. identification: yup.string().min(7, "請輸入證件號碼").required('請輸入證件號碼'),
  42. checkDigit: yup.string().max(1).required('請輸入括號內的數字或字母').nullable(),
  43. idDocType: yup.string().max(255).required('請輸入證件類別'),
  44. tel_countryCode: yup.string().min(3, '請輸入3位數字').required('請輸入國際區號'),
  45. fax_countryCode: yup.string().min(3, '請輸入3位數字'),
  46. phoneNumber: yup.string().min(8, '請輸入8位數字').required('請輸入聯絡電話'),
  47. faxNumber: yup.string().min(8, '請輸入8位數字').nullable(),
  48. }),
  49. onSubmit: values => {
  50. console.log(values);
  51. HttpUtils.post({
  52. url: UrlUtils.POST_IND_USER + "/" + formData.id,
  53. params: {
  54. prefix: values.prefix,
  55. enName: values.enName,
  56. chName: values.chName,
  57. idDocType: values.idDocType,
  58. mobileNumber: {
  59. countryCode: values.tel_countryCode,
  60. phoneNumber: values.phoneNumber
  61. },
  62. identification: values.identification,
  63. checkDigit: values.checkDigit,
  64. faxNo: {
  65. countryCode: values.fax_countryCode,
  66. faxNumber: values.faxNumber
  67. },
  68. emailAddress: values.emailAddress,
  69. address: {
  70. country: values.country,
  71. district: values.district,
  72. addressLine1: values.addressLine1,
  73. addressLine2: values.addressLine2,
  74. addressLine3: values.addressLine3,
  75. },
  76. },
  77. onSuccess: function () {
  78. notifySaveSuccess();
  79. loadDataFun();
  80. }
  81. });
  82. }
  83. });
  84. useEffect(() => {
  85. if (Object.keys(formData).length > 0) {
  86. setCurrentUserData(formData);
  87. }
  88. }, [formData]);
  89. useEffect(() => {
  90. setLocked(currentUserData.locked);
  91. }, [currentUserData]);
  92. const onEditClick = () => {
  93. setEditMode(true);
  94. };
  95. const onVerifiedClick = () => {
  96. HttpUtils.get({
  97. url: UrlUtils.GET_IND_USER_VERIFY + "/" + formData.id,
  98. onSuccess: function () {
  99. notifyVerifySuccess()
  100. loadDataFun();
  101. }
  102. });
  103. };
  104. const doLock = () => {
  105. HttpUtils.get({
  106. url: UrlUtils.GET_USER_LOCK + "/" + formData.id,
  107. onSuccess: function () {
  108. notifyLockSuccess()
  109. loadDataFun();
  110. }
  111. });
  112. };
  113. const doUnlock = () => {
  114. HttpUtils.get({
  115. url: UrlUtils.GET_USER_UNLOCK + "/" + formData.id,
  116. onSuccess: function () {
  117. notifyActiveSuccess()
  118. loadDataFun();
  119. }
  120. });
  121. };
  122. return (
  123. <MainCard elevation={0}
  124. border={false}
  125. content={false}
  126. >
  127. {!onReady ?
  128. <LoadingComponent />
  129. :
  130. <form onSubmit={formik.handleSubmit} style={{ padding: 12 }}>
  131. {/*top button*/}
  132. <Grid item xs={12} sm={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  133. <Grid container maxWidth justifyContent="flex-start">
  134. {editMode ?
  135. <>
  136. <Grid item sx={{ mr: 3 }}>
  137. <Button
  138. size="large"
  139. variant="contained"
  140. onClick={loadDataFun}
  141. sx={{
  142. textTransform: 'capitalize',
  143. alignItems: 'end'
  144. }}
  145. >
  146. <Typography variant="h5">Reset & Back</Typography>
  147. </Button>
  148. </Grid>
  149. <Grid item sx={{ ml: 3, mr: 3 }}>
  150. <Button
  151. size="large"
  152. variant="contained"
  153. type="submit"
  154. color="success"
  155. sx={{
  156. textTransform: 'capitalize',
  157. alignItems: 'end'
  158. }}
  159. >
  160. <Typography variant="h5">Save</Typography>
  161. </Button>
  162. </Grid>
  163. </>
  164. :
  165. <>
  166. <Grid item sx={{ mr: 3 }}>
  167. <Button
  168. size="large"
  169. variant="contained"
  170. sx={{
  171. textTransform: 'capitalize',
  172. alignItems: 'end'
  173. }}
  174. onClick={onEditClick}
  175. >
  176. <Typography variant="h5">Edit</Typography>
  177. </Button>
  178. </Grid>
  179. </>
  180. }
  181. </Grid>
  182. </Grid>
  183. {/*end top button*/}
  184. <Typography variant="h4" sx={{ mt: 3, mb: 2, borderBottom: "1px solid black" }}>
  185. Individual User Details
  186. </Typography>
  187. <Grid item xs={12} sm={12} md={12} lg={12}>
  188. <Grid container>
  189. <Grid item xs={12} sm={12} md={12} lg={4} >
  190. {FieldUtils.getTextField({
  191. label: "Username:",
  192. valueName: "username",
  193. disabled: true,
  194. form: formik
  195. })}
  196. </Grid>
  197. <Grid item xs={12} sm={12} md={12} lg={4}>
  198. {FieldUtils.getTextField({
  199. label: "English Name:",
  200. valueName: "enName",
  201. disabled: (!editMode),
  202. form: formik
  203. })}
  204. </Grid>
  205. <Grid item xs={12} sm={12} md={12} lg={4}>
  206. {FieldUtils.getTextField({
  207. label: "Created Date:",
  208. valueName: "createDate",
  209. disabled: true,
  210. form: formik
  211. })}
  212. </Grid>
  213. <Grid item xs={12} sm={12} md={12} lg={4}>
  214. {FieldUtils.getTextField({
  215. label: "Prefix:",
  216. valueName: "prefix",
  217. disabled: (!editMode),
  218. form: formik
  219. })}
  220. </Grid>
  221. <Grid item xs={12} sm={12} md={12} lg={4}>
  222. {FieldUtils.getTextField({
  223. label: "Chinese Name:",
  224. valueName: "chName",
  225. disabled: (!editMode),
  226. form: formik
  227. })}
  228. </Grid>
  229. <Grid item xs={12} sm={12} md={12} lg={4}>
  230. {FieldUtils.getTextField({
  231. label: "Last Updated:",
  232. valueName: "modifieDate",
  233. disabled: true,
  234. form: formik
  235. })}
  236. </Grid>
  237. <Grid item xs={12} sm={12} md={12} lg={4}>
  238. {FieldUtils.getComboField({
  239. label: "ID Type:",
  240. valueName: "idDocType",
  241. disabled: (!editMode),
  242. dataList: ComboData.idDocType,
  243. filterOptions: (options) => options,
  244. getOptionLabel: (item) => item ? typeof item === 'string' ? item : (item["type"] ? item["type"] + "-" + item["label"] : "") : "",
  245. onInputChange: (event, newValue, setInputValue) => {
  246. if (newValue == null) {
  247. setInputValue("");
  248. }
  249. let _val = newValue.split("-");
  250. if (_val[0]) {
  251. setInputValue(_val[0]);
  252. }
  253. },
  254. onChange: (event, newValue) => {
  255. if (newValue == null) {
  256. formik.setFieldValue("idDocType", "");
  257. return;
  258. }
  259. formik.setFieldValue("idDocType", newValue.type);
  260. },
  261. form: formik
  262. })}
  263. </Grid>
  264. <Grid item xs={12} sm={12} md={12} lg={4}>
  265. {FieldUtils.getPhoneField({
  266. label: "Contact Tel:",
  267. valueName: {
  268. code: "tel_countryCode",
  269. num: "phoneNumber"
  270. },
  271. disabled: (!editMode),
  272. form: formik
  273. })}
  274. </Grid>
  275. <Grid item xs={12} sm={12} md={12} lg={4}>
  276. <Grid container alignItems={"center"}>
  277. <Grid item xs={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  278. <Typography variant="h5">Verified:</Typography>
  279. </Grid>
  280. {
  281. currentUserData.verifiedBy || editMode ?
  282. <Grid item xs={12} sm={12} md={6} lg={6} sx={{mb:2}}>
  283. {FieldUtils.initField({
  284. valueName: "verifiedStatus",
  285. disabled: true,
  286. form: formik,
  287. })}
  288. </Grid>
  289. :
  290. <>
  291. <Grid item xs={8} sm={8} md={6} lg={4} sx={{mb:2}}>
  292. {FieldUtils.initField({
  293. valueName: "verifiedStatus",
  294. disabled: true,
  295. form: formik,
  296. })}
  297. </Grid>
  298. <Grid item xs={2} sm={2} md={2} lg={2} sx={{ml:2 ,mb:2}}>
  299. <Button
  300. variant="contained"
  301. sx={{
  302. textTransform: 'capitalize',
  303. alignItems: 'end',
  304. }}
  305. onClick={onVerifiedClick}
  306. >
  307. <Typography variant="h5">Verify</Typography>
  308. </Button>
  309. </Grid>
  310. </>
  311. }
  312. </Grid>
  313. </Grid>
  314. <Grid xs={12} sm={12} md={12} lg={4}>
  315. <Grid container alignItems={"center"} sx={{mb:2}}>
  316. <Grid item xs={12} sm={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  317. <Typography variant="h5">ID No.:</Typography>
  318. </Grid>
  319. <Grid item xs={12} sm={12} md={9} lg={6}>
  320. <Grid container>
  321. {formik.values.idDocType === "HKID" ?
  322. <>
  323. <Grid item xs={6} sm={6} md={6} lg={7.5} sx={{mr:1}}>
  324. {FieldUtils.initField({
  325. valueName: "identification",
  326. disabled: (!editMode),
  327. form: formik,
  328. placeholder: "證件號碼",
  329. inputProps: {
  330. maxLength: 7,
  331. onKeyDown: (e) => {
  332. if (e.key === 'Enter') {
  333. e.preventDefault();
  334. }
  335. },
  336. }
  337. })}
  338. </Grid>
  339. <Grid item xs={2} sm={2} md={2} lg={2}>
  340. {FieldUtils.initField({
  341. valueName: "checkDigit",
  342. disabled: (!editMode),
  343. form: formik
  344. })}
  345. </Grid>
  346. </> :
  347. <Grid item xs={12} sm={6} md={6} lg={12}>
  348. {FieldUtils.initField({
  349. valueName: "identification",
  350. disabled: (!editMode),
  351. form: formik
  352. })}
  353. </Grid>
  354. }
  355. </Grid>
  356. </Grid>
  357. </Grid>
  358. </Grid>
  359. <Grid item xs={12} sm={12} md={12} lg={4}>
  360. {FieldUtils.getPhoneField({
  361. label: "Fax No.:",
  362. valueName: {
  363. code: "fax_countryCode",
  364. num: "faxNumber"
  365. },
  366. disabled: (!editMode),
  367. form: formik
  368. })}
  369. </Grid>
  370. <Grid item xs={12} sm={12} md={12} lg={4}>
  371. {FieldUtils.getTextField({
  372. label: "Last Login:",
  373. valueName: "lastLoginDate",
  374. disabled: true,
  375. form: formik
  376. })}
  377. </Grid>
  378. <Grid item xs={12} sm={12} md={12} lg={4}>
  379. {FieldUtils.getComboField({
  380. label: "Country:",
  381. valueName: "country",
  382. dataList: ComboData.country,
  383. disabled: (!editMode),
  384. form: formik
  385. })}
  386. </Grid>
  387. <Grid item xs={12} sm={12} md={12} lg={4}>
  388. {FieldUtils.getTextField({
  389. label: "Email:",
  390. valueName: "emailAddress",
  391. disabled: (!editMode),
  392. form: formik
  393. })}
  394. </Grid>
  395. <Grid item xs={12} sm={12} md={12} lg={4}>
  396. <Grid container alignItems={"center"} sx={{mb:2}}>
  397. <Grid item xs={12} sm={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  398. <Typography variant="h5">Status:</Typography>
  399. </Grid>
  400. {
  401. editMode ?
  402. <Grid item xs={8} sm={8} md={6} lg={6}>
  403. {FieldUtils.initField({
  404. valueName: "status",
  405. disabled: true,
  406. form: formik,
  407. })}
  408. </Grid>
  409. :
  410. <>
  411. <Grid item xs={8} sm={8} md={6} lg={4}>
  412. {FieldUtils.initField({
  413. valueName: "status",
  414. disabled: true,
  415. form: formik,
  416. })}
  417. </Grid>
  418. {locked ?
  419. <Grid item xs={2} sm={2} md={2} lg={2} sx={{ml:2}}>
  420. <Button
  421. variant="contained"
  422. color="success"
  423. sx={{
  424. textTransform: 'capitalize',
  425. alignItems: 'end'
  426. }}
  427. onClick={doUnlock}
  428. >
  429. <Typography variant="h5">Active</Typography>
  430. </Button>
  431. </Grid>
  432. :
  433. <Grid item xs={2} sm={2} md={2} lg={2} sx={{ml:2}}>
  434. <Button
  435. variant="contained"
  436. color="error"
  437. sx={{
  438. textTransform: 'capitalize',
  439. alignItems: 'end'
  440. }}
  441. onClick={doLock}
  442. >
  443. <Typography variant="h5">Lock</Typography>
  444. </Button>
  445. </Grid>
  446. }
  447. </>
  448. }
  449. </Grid>
  450. </Grid>
  451. <Grid item xs={12} sm={12} md={12} lg={4}>
  452. {FieldUtils.getAddressField({
  453. label: "Address:",
  454. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  455. disabled: (!editMode),
  456. form: formik
  457. })}
  458. </Grid>
  459. <Grid item xs={12} sm={12} md={12} lg={4}>
  460. {FieldUtils.getComboField({
  461. label: "District:",
  462. valueName: "district",
  463. dataList: ComboData.district,
  464. disabled: (!editMode),
  465. form: formik
  466. })}
  467. </Grid>
  468. </Grid>
  469. </Grid>
  470. </form>
  471. }
  472. </MainCard>
  473. );
  474. };
  475. export default UserInformationCard_Individual;