No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

595 líneas
32 KiB

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