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.
 
 

342 Zeilen
17 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 {notifySaveSuccess,} from 'utils/CommonFunction';
  18. import {FormattedMessage, useIntl} from "react-intl";
  19. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  20. import {ThemeProvider} from "@emotion/react";
  21. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  22. const UserInformationCard_Individual_Pub = ({ formData, loadDataFun }) => {
  23. const intl = useIntl();
  24. const [currentUserData, setCurrentUserData] = useState(formData);
  25. const [editMode, setEditMode] = useState(false);
  26. const [onReady, setOnReady] = useState(false);
  27. useEffect(() => {
  28. //if state data are ready and assign to different field
  29. // console.log(currentApplicationDetailData)
  30. if (Object.keys(currentUserData).length > 0) {
  31. setOnReady(true);
  32. }
  33. }, [currentUserData]);
  34. const formik = useFormik({
  35. enableReinitialize: true,
  36. initialValues: currentUserData,
  37. validationSchema: yup.object().shape({
  38. enName: yup.string().max(255).required(intl.formatMessage({id: 'userRequireEnglishName'})),
  39. chName: yup.string().max(255).required(intl.formatMessage({id: 'userRequireChineseName'})),
  40. addressLine1: yup.string().max(255).required(intl.formatMessage({id: 'validateAddressLine1'})),
  41. addressLine2: yup.string().max(255).nullable(),
  42. addressLine3: yup.string().max(255).nullable(),
  43. emailAddress: yup.string().email(intl.formatMessage({id: 'validEmailFormat'})).max(255).required(intl.formatMessage({id: 'requireEmail'})),
  44. tel_countryCode: yup.string().min(3, intl.formatMessage({id: 'require3Number'})).required(intl.formatMessage({id: 'requireDialingCode'})),
  45. fax_countryCode: yup.string().min(3, intl.formatMessage({id: 'require3Number'})),
  46. phoneNumber: yup.string().min(8, intl.formatMessage({id: 'require8Number'})).required(intl.formatMessage({id: 'requireContactNumber'})),
  47. faxNumber: yup.string().min(8, intl.formatMessage({id: 'require8Number'})).nullable(),
  48. }),
  49. onSubmit: values => {
  50. console.log(values);
  51. HttpUtils.post({
  52. url: UrlUtils.POST_PUB_IND_USER,
  53. params: {
  54. enName: values.enName,
  55. chName: values.chName,
  56. mobileNumber: {
  57. countryCode: values.tel_countryCode,
  58. phoneNumber: values.phoneNumber
  59. },
  60. faxNo: {
  61. countryCode: values.fax_countryCode,
  62. faxNumber: values.faxNumber
  63. },
  64. address: {
  65. country: values.country.key,
  66. district: values.district.key,
  67. addressLine1: values.addressLine1,
  68. addressLine2: values.addressLine2,
  69. addressLine3: values.addressLine3,
  70. },
  71. },
  72. onSuccess: function () {
  73. notifySaveSuccess();
  74. loadDataFun();
  75. }
  76. });
  77. }
  78. });
  79. useEffect(() => {
  80. if (Object.keys(formData).length > 0) {
  81. setCurrentUserData(formData);
  82. }
  83. }, [formData]);
  84. useEffect(() => {
  85. }, [currentUserData]);
  86. const onEditClick = () => {
  87. setEditMode(true);
  88. };
  89. return (
  90. <MainCard elevation={0}
  91. border={false}
  92. content={false}
  93. >
  94. {!onReady ?
  95. <LoadingComponent />
  96. :
  97. <form onSubmit={formik.handleSubmit} style={{ padding: 12 }}>
  98. {/*top button*/}
  99. <Grid item xs={12} sm={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  100. <Grid container maxWidth justifyContent="flex-start">
  101. {editMode ?
  102. <>
  103. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  104. <Grid item sx={{ mr: 3 }}>
  105. <Button
  106. aria-label={intl.formatMessage({id: 'back'})}
  107. variant="contained"
  108. color="cancel"
  109. onClick={loadDataFun}
  110. >
  111. <FormattedMessage id="resetAndBack" />
  112. </Button>
  113. </Grid>
  114. <Grid item sx={{ ml: 3, mr: 3 }}>
  115. <Button
  116. aria-label={intl.formatMessage({id: 'save'})}
  117. variant="contained"
  118. type="submit"
  119. color="success"
  120. >
  121. <FormattedMessage id="save" />
  122. </Button>
  123. </Grid>
  124. </ThemeProvider>
  125. </>
  126. :
  127. <>
  128. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  129. <Grid item sx={{ mr: 3 }}>
  130. <Button
  131. aria-label={intl.formatMessage({id: 'edit'})}
  132. variant="contained"
  133. onClick={onEditClick}
  134. >
  135. <FormattedMessage id="edit" />
  136. </Button>
  137. </Grid>
  138. </ThemeProvider>
  139. </>
  140. }
  141. </Grid>
  142. </Grid>
  143. {/*end top button*/}
  144. <Typography variant="h4" sx={{ mt: 3, mb: 2, borderBottom: "1px solid black" }}>
  145. <FormattedMessage id="userDetail" />
  146. </Typography>
  147. <Grid item xs={12} sm={12} md={12} lg={12}>
  148. <Grid container>
  149. <Grid item xs={12} sm={12} md={12} lg={4} >
  150. {FieldUtils.getTextField({
  151. label: intl.formatMessage({id: 'userLoginName'}) + ":",
  152. valueName: "username",
  153. disabled: true,
  154. form: formik
  155. })}
  156. </Grid>
  157. <Grid item xs={12} sm={12} md={12} lg={4}>
  158. {FieldUtils.getTextField({
  159. label: intl.formatMessage({id: 'userEnglishName'}) + ":",
  160. valueName: "enName",
  161. disabled: true,
  162. form: formik
  163. })}
  164. </Grid>
  165. <Grid item xs={12} sm={12} md={12} lg={4}>
  166. {FieldUtils.getTextField({
  167. label: intl.formatMessage({id: 'userChineseName'}) + ":",
  168. valueName: "chName",
  169. disabled: true,
  170. form: formik
  171. })}
  172. </Grid>
  173. <Grid item xs={12} sm={12} md={12} lg={4}>
  174. {FieldUtils.getComboField({
  175. label: intl.formatMessage({id: 'idType'}) + ":",
  176. valueName: "idDocType",
  177. disabled: true,
  178. dataList: ComboData.idDocType,
  179. filterOptions: (options) => options,
  180. getOptionLabel: (item) => item ? typeof item === 'string' ? item : (item["type"] ? item["type"] + "-" + item["label"] : "") : "",
  181. onInputChange: (event, newValue, setInputValue) => {
  182. if (newValue == null) {
  183. setInputValue("");
  184. }
  185. let _val = newValue.split("-");
  186. if (_val[0]) {
  187. setInputValue(_val[0]);
  188. }
  189. },
  190. onChange: (event, newValue) => {
  191. if (newValue == null) {
  192. formik.setFieldValue("idDocType", "");
  193. return;
  194. }
  195. formik.setFieldValue("idDocType", newValue.type);
  196. },
  197. form: formik
  198. })}
  199. </Grid>
  200. <Grid xs={12} sm={12} md={12} lg={4}>
  201. <Grid container alignItems={"center"} sx={{mb:2}}>
  202. <Grid item xs={12} sm={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  203. <Typography variant="pnspsFormParagraphBold">
  204. <FormattedMessage id="idNo" />:
  205. </Typography>
  206. </Grid>
  207. <Grid item xs={12} sm={12} md={9} lg={6}>
  208. <Grid container>
  209. {formik.values.idDocType === "HKID" ?
  210. <>
  211. <Grid item xs={6} sm={6} md={6} lg={7.5} sx={{mr:1}}>
  212. {FieldUtils.initField({
  213. valueName: "identification",
  214. disabled: true,
  215. form: formik,
  216. placeholder: intl.formatMessage({id: 'idDocNumber'}),
  217. inputProps: {
  218. maxLength: 7,
  219. onKeyDown: (e) => {
  220. if (e.key === 'Enter') {
  221. e.preventDefault();
  222. }
  223. },
  224. }
  225. })}
  226. </Grid>
  227. <Grid item xs={2} sm={2} md={2} lg={2}>
  228. {FieldUtils.initField({
  229. valueName: "checkDigit",
  230. disabled: true,
  231. form: formik
  232. })}
  233. </Grid>
  234. </> :
  235. <Grid item xs={12} sm={6} md={6} lg={12}>
  236. {FieldUtils.initField({
  237. valueName: "identification",
  238. disabled: true,
  239. form: formik
  240. })}
  241. </Grid>
  242. }
  243. </Grid>
  244. </Grid>
  245. </Grid>
  246. </Grid>
  247. <Grid item xs={12} sm={12} md={12} lg={4}>
  248. {FieldUtils.getPhoneField({
  249. label: intl.formatMessage({id: 'userContactNumber'}) + ":",
  250. valueName: {
  251. code: "tel_countryCode",
  252. num: "phoneNumber"
  253. },
  254. disabled: (!editMode),
  255. form: formik
  256. })}
  257. </Grid>
  258. <Grid item xs={12} sm={12} md={12} lg={4}>
  259. {FieldUtils.getComboField({
  260. label: intl.formatMessage({id: 'country'}) + ":",
  261. valueName: "country",
  262. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  263. dataList: ComboData.country,
  264. disabled: (!editMode),
  265. form: formik
  266. })}
  267. </Grid>
  268. <Grid item xs={12} sm={12} md={12} lg={4}>
  269. {FieldUtils.getTextField({
  270. label: intl.formatMessage({id: 'userContactEmail'}) + ":",
  271. valueName: "emailAddress",
  272. disabled: true,
  273. form: formik
  274. })}
  275. </Grid>
  276. <Grid item xs={12} sm={12} md={12} lg={4}>
  277. {FieldUtils.getPhoneField({
  278. label: intl.formatMessage({id: 'userFaxNumber'}) + ":",
  279. valueName: {
  280. code: "fax_countryCode",
  281. num: "faxNumber"
  282. },
  283. disabled: (!editMode),
  284. form: formik
  285. })}
  286. </Grid>
  287. <Grid item xs={12} sm={12} md={12} lg={4}>
  288. {FieldUtils.getAddressField({
  289. label: intl.formatMessage({id: 'userAddress'}) + ":",
  290. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  291. disabled: (!editMode),
  292. form: formik
  293. })}
  294. </Grid>
  295. <Grid item xs={12} sm={12} md={12} lg={4}>
  296. {FieldUtils.getComboField({
  297. label: intl.formatMessage({id: 'district'}) + ":",
  298. valueName: "district",
  299. dataList: ComboData.district,
  300. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  301. disabled: (!editMode),
  302. form: formik
  303. })}
  304. </Grid>
  305. </Grid>
  306. </Grid>
  307. </form>
  308. }
  309. </MainCard>
  310. );
  311. };
  312. export default UserInformationCard_Individual_Pub;