Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UserInformationCard_Individual_Pub.js 22 KiB

vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 * as React from "react";
  10. import { useEffect, useState } from "react";
  11. import * as yup from 'yup';
  12. import { useFormik } from 'formik';
  13. import * as FieldUtils from "utils/FieldUtils";
  14. import * as HttpUtils from 'utils/HttpUtils';
  15. import * as UrlUtils from "utils/ApiPathConst";
  16. import * as ComboData from "utils/ComboData";
  17. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  18. import Loadable from 'components/Loadable';
  19. import { lazy } from 'react';
  20. import {notifySaveSuccess,} from 'utils/CommonFunction';
  21. import {FormattedMessage, useIntl} from "react-intl";
  22. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  23. import {ThemeProvider} from "@emotion/react";
  24. import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons';
  25. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  26. const UserInformationCard_Individual_Pub = ({ formData, loadDataFun }) => {
  27. const intl = useIntl();
  28. const [currentUserData, setCurrentUserData] = useState({});
  29. const [editMode, setEditMode] = 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 (Object.keys(formData).length > 0) {
  41. setCurrentUserData(formData);
  42. }
  43. }, [formData]);
  44. useEffect(() => {
  45. //if state data are ready and assign to different field
  46. // console.log(currentApplicationDetailData)
  47. if (Object.keys(currentUserData).length > 0) {
  48. setOnReady(true);
  49. }
  50. }, [currentUserData]);
  51. function getMaxErrStr(num, fieldname){
  52. return intl.formatMessage({ id: 'noMoreThenNWords' },{num:num, fieldname:fieldname?intl.formatMessage({ id: fieldname})+": ":""});
  53. }
  54. const formik = useFormik({
  55. enableReinitialize: true,
  56. initialValues: currentUserData,
  57. validationSchema: yup.object().shape({
  58. enName: yup.string().max(40, getMaxErrStr(40)).when('chName', {
  59. is: (chName) => chName?false:true,
  60. then: yup.string().required(intl.formatMessage({ id: 'userRequireEnglishName' }))
  61. }).nullable(),
  62. chName: yup.string().max(6, getMaxErrStr(6)).nullable(),
  63. addressLine1: yup.string().max(40).required(intl.formatMessage({id: 'validateAddressLine1'})),
  64. addressLine2: yup.string().max(40).nullable(),
  65. addressLine3: yup.string().max(40).nullable(),
  66. emailAddress: yup.string().email(intl.formatMessage({id: 'validEmailFormat'})).max(255).required(intl.formatMessage({id: 'requireEmail'})),
  67. tel_countryCode: yup.string().min(3, intl.formatMessage({id: 'require3Number'})).required(intl.formatMessage({id: 'requireDialingCode'})),
  68. fax_countryCode: yup.string().min(3, intl.formatMessage({id: 'require3Number'})),
  69. phoneNumber: yup.string().min(8, intl.formatMessage({id: 'require8Number'})).required(intl.formatMessage({id: 'requireContactNumber'})),
  70. faxNumber: yup.string().min(8, intl.formatMessage({id: 'require8Number'})).nullable(),
  71. }),
  72. onSubmit: (values, { setSubmitting }) => {
  73. if (values.country == null) {
  74. setErrorMsg(intl.formatMessage({ id: 'pleaseFillInCountry' }));
  75. return;
  76. }
  77. if (values.country.type === "hongKong" && values.district == null) {
  78. setErrorMsg(intl.formatMessage({ id: 'pleaseFillInDistrict' }));
  79. return;
  80. }
  81. return new Promise((resolve) => {
  82. HttpUtils.post({
  83. url: UrlUtils.POST_PUB_IND_USER,
  84. params: {
  85. enName: values.enName,
  86. chName: values.chName,
  87. mobileNumber: {
  88. countryCode: values.tel_countryCode,
  89. phoneNumber: values.phoneNumber
  90. },
  91. faxNo: {
  92. countryCode: values.fax_countryCode,
  93. faxNumber: values.faxNumber
  94. },
  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. resolve();
  107. window.location.reload();
  108. },
  109. onFail: function () {
  110. setSubmitting(false);
  111. resolve();
  112. },
  113. onError: function () {
  114. setSubmitting(false);
  115. resolve();
  116. }
  117. });
  118. });
  119. }
  120. });
  121. const onEditClick = () => {
  122. setEditMode(true);
  123. };
  124. return (
  125. <MainCard elevation={0}
  126. border={false}
  127. content={false}
  128. >
  129. {!onReady ?
  130. <LoadingComponent />
  131. :
  132. <form onSubmit={formik.handleSubmit} style={{ padding: 12 }}>
  133. {/*top button*/}
  134. <Grid item xs={12} sm={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  135. <Grid container maxWidth justifyContent="flex-start">
  136. {editMode ?
  137. <>
  138. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  139. <Grid item sx={{ mr: 3 }}>
  140. <Button
  141. aria-label={intl.formatMessage({id: 'back'})}
  142. variant="contained"
  143. color="cancel"
  144. onClick={loadDataFun}
  145. disabled={formik.isSubmitting}
  146. >
  147. <FormattedMessage id="resetAndBack" />
  148. </Button>
  149. </Grid>
  150. <Grid item sx={{ ml: 3, mr: 3 }}>
  151. <Button
  152. aria-label={intl.formatMessage({id: 'save'})}
  153. variant="contained"
  154. type="submit"
  155. color="success"
  156. disabled={formik.isSubmitting}
  157. >
  158. <FormattedMessage id="save" />
  159. </Button>
  160. </Grid>
  161. </ThemeProvider>
  162. </>
  163. :
  164. <>
  165. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  166. <Grid item sx={{ mr: 3 }}>
  167. <Button
  168. aria-label={intl.formatMessage({id: 'edit'})}
  169. variant="contained"
  170. onClick={onEditClick}
  171. >
  172. <FormattedMessage id="edit" />
  173. </Button>
  174. </Grid>
  175. </ThemeProvider>
  176. </>
  177. }
  178. </Grid>
  179. </Grid>
  180. {/*end top button*/}
  181. {/* <Typography variant="h4" sx={{ mt: 3, mb: 2, borderBottom: "1px solid black" }}>
  182. <FormattedMessage id="userDetail" />
  183. </Typography> */}
  184. <Grid item xs={12} sm={12} md={12} lg={12}>
  185. <Grid container>
  186. <Grid item xs={12}>
  187. <FormHelperText error id="helper-text-address1-signup">
  188. <Typography variant="errorMessage1">
  189. {errorMsg}
  190. </Typography>
  191. </FormHelperText>
  192. </Grid>
  193. <Grid item xs={12} sm={12} md={12} lg={4} >
  194. {FieldUtils.getTextField({
  195. label: intl.formatMessage({id: 'userLoginName'}) + ":",
  196. valueName: "username",
  197. disabled: true,
  198. form: formik
  199. })}
  200. </Grid>
  201. <Grid item xs={12} sm={12} md={12} lg={4}>
  202. {FieldUtils.getTextField({
  203. label: intl.formatMessage({id: 'userEnglishName'}) + ":",
  204. valueName: "enName",
  205. disabled: true,
  206. form: formik
  207. })}
  208. </Grid>
  209. <Grid item xs={12} sm={12} md={12} lg={4}>
  210. {FieldUtils.getTextField({
  211. label: intl.formatMessage({id: 'userChineseName'}) + ":",
  212. valueName: "chName",
  213. disabled: true,
  214. form: formik
  215. })}
  216. </Grid>
  217. <Grid item xs={12} sm={12} md={12} lg={4}>
  218. {FieldUtils.getComboField({
  219. label: intl.formatMessage({id: 'idType'}) + ":",
  220. valueName: "idDocType",
  221. disabled: true,
  222. dataList: ComboData.idDocType,
  223. getOptionLabel: (option) => option? intl.formatMessage({ id: option }) : "",
  224. form: formik
  225. })}
  226. </Grid>
  227. <Grid xs={12} sm={12} md={12} lg={4}>
  228. <Grid container alignItems={"center"} spacing={1} sx={{mb:2}} >
  229. <Grid item xs={12} sm={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  230. <Typography variant="pnspsFormParagraphBold">
  231. <FormattedMessage id="idNo" />:
  232. </Typography>
  233. </Grid>
  234. <Grid item xs={12} sm={12} md={9} lg={6}>
  235. <Grid container>
  236. {formik.values.idDocType === "HKID" ?
  237. // <>
  238. // <Grid item xs={6} sm={6} md={6} lg={7.5} sx={{mr:1}}>
  239. // {FieldUtils.initField({
  240. // valueName: "identification",
  241. // disabled: true,
  242. // form: formik,
  243. // placeholder: intl.formatMessage({id: 'idDocNumber'}),
  244. // inputProps: {
  245. // maxLength: 7,
  246. // onKeyDown: (e) => {
  247. // if (e.key === 'Enter') {
  248. // e.preventDefault();
  249. // }
  250. // },
  251. // }
  252. // })}
  253. // </Grid>
  254. // <Grid item xs={2} sm={2} md={2} lg={2} style={{minWidth:40}}>
  255. // {FieldUtils.initField({
  256. // valueName: "checkDigit",
  257. // disabled: true,
  258. // form: formik,
  259. // })}
  260. // </Grid>
  261. // </>
  262. <Stack direction="row">
  263. <Typography variant="h5" mt={1}>
  264. {formik.values.identification?.slice(0, 4)}
  265. </Typography>
  266. <Typography variant="h5"mt={1}>
  267. {/* {showId ?formik.values.identification.slice(4):"****"}{showId ? '(' + formik.values.checkDigit + ')' :null} */}
  268. {showId ? formik.values.identification?.slice(4) : "****"}{showId ? formik.values.checkDigit?'(' +formik.values.checkDigit+ ')': "()" : ""}
  269. </Typography>
  270. <IconButton
  271. aria-label={intl.formatMessage({ id: 'ariaToggleIdVisibility' })}
  272. onClick={handleClickShowId}
  273. onMouseDown={handleMouseDownId}
  274. edge="end"
  275. size="large"
  276. >
  277. {showId ? <EyeOutlined /> : <EyeInvisibleOutlined />}
  278. </IconButton>
  279. </Stack>
  280. :
  281. // <Grid item xs={10} sm={4} md={4} lg={10}>
  282. // {FieldUtils.initField({
  283. // valueName: "identification",
  284. // disabled: true,
  285. // form: formik
  286. // })}
  287. // </Grid>
  288. <Stack direction="row">
  289. <Typography variant="h5" mt={1}>
  290. {formik.values.identification?.slice(0, 4)}
  291. </Typography>
  292. <Typography variant="h5"mt={1}>
  293. {showId ?formik.values.identification?.slice(4):"****"}
  294. </Typography>
  295. <IconButton
  296. aria-label={intl.formatMessage({ id: 'ariaToggleIdVisibility' })}
  297. onClick={handleClickShowId}
  298. onMouseDown={handleMouseDownId}
  299. edge="end"
  300. size="large"
  301. >
  302. {showId ? <EyeOutlined /> : <EyeInvisibleOutlined />}
  303. </IconButton>
  304. </Stack>
  305. }
  306. </Grid>
  307. </Grid>
  308. </Grid>
  309. </Grid>
  310. <Grid item xs={12} sm={12} md={12} lg={4}>
  311. {FieldUtils.getPhoneField({
  312. label: intl.formatMessage({id: 'userContactNumber'}) + ":",
  313. valueName: {
  314. code: "tel_countryCode",
  315. num: "phoneNumber"
  316. },
  317. disabled: (!editMode),
  318. form: formik
  319. })}
  320. </Grid>
  321. <Grid item xs={12} sm={12} md={12} lg={4}>
  322. {FieldUtils.getComboField({
  323. label: intl.formatMessage({id: 'language'}) + ":",
  324. valueName: "preferLocale",
  325. dataList: ComboData.Locale,
  326. getOptionLabel: (option) => option.label? option.label: "",
  327. disabled: (!editMode),
  328. form: formik
  329. })}
  330. </Grid>
  331. <Grid item xs={12} sm={12} md={12} lg={4}>
  332. {FieldUtils.getTextField({
  333. label: intl.formatMessage({id: 'userContactEmail'}) + ":",
  334. valueName: "emailAddress",
  335. disabled: true,
  336. form: formik
  337. })}
  338. </Grid>
  339. <Grid item xs={12} sm={12} md={12} lg={4}>
  340. {FieldUtils.getPhoneField({
  341. label: intl.formatMessage({id: 'userFaxNumber'}) + ":",
  342. valueName: {
  343. code: "fax_countryCode",
  344. num: "faxNumber"
  345. },
  346. disabled: (!editMode),
  347. form: formik
  348. })}
  349. </Grid>
  350. <Grid item xs={12} sm={12} md={12} lg={12}>
  351. {FieldUtils.getAddressField({
  352. label: intl.formatMessage({id: 'userAddress'}) + ":",
  353. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  354. disabled: (!editMode),
  355. form: formik
  356. })}
  357. </Grid>
  358. <Grid item xs={12} sm={12} md={12} lg={12}>
  359. {FieldUtils.getProfileComboField({
  360. label: "",
  361. valueName: "district",
  362. dataList: ComboData.district,
  363. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  364. disabled: (!editMode),
  365. form: formik
  366. })}
  367. </Grid>
  368. <Grid item xs={12} sm={12} md={12} lg={12}>
  369. {FieldUtils.getProfileComboField({
  370. label: "",
  371. valueName: "country",
  372. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  373. dataList: ComboData.country,
  374. disabled: true,
  375. form: formik
  376. })}
  377. </Grid>
  378. </Grid>
  379. </Grid>
  380. </form>
  381. }
  382. </MainCard>
  383. );
  384. };
  385. export default UserInformationCard_Individual_Pub;