Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

341 linhas
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. onClick={loadDataFun}
  109. >
  110. <FormattedMessage id="resetAndBack" />
  111. </Button>
  112. </Grid>
  113. <Grid item sx={{ ml: 3, mr: 3 }}>
  114. <Button
  115. aria-label={intl.formatMessage({id: 'save'})}
  116. variant="contained"
  117. type="submit"
  118. color="success"
  119. >
  120. <FormattedMessage id="save" />
  121. </Button>
  122. </Grid>
  123. </ThemeProvider>
  124. </>
  125. :
  126. <>
  127. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  128. <Grid item sx={{ mr: 3 }}>
  129. <Button
  130. aria-label={intl.formatMessage({id: 'edit'})}
  131. variant="contained"
  132. onClick={onEditClick}
  133. >
  134. <FormattedMessage id="edit" />
  135. </Button>
  136. </Grid>
  137. </ThemeProvider>
  138. </>
  139. }
  140. </Grid>
  141. </Grid>
  142. {/*end top button*/}
  143. <Typography variant="h4" sx={{ mt: 3, mb: 2, borderBottom: "1px solid black" }}>
  144. <FormattedMessage id="userDetail" />
  145. </Typography>
  146. <Grid item xs={12} sm={12} md={12} lg={12}>
  147. <Grid container>
  148. <Grid item xs={12} sm={12} md={12} lg={4} >
  149. {FieldUtils.getTextField({
  150. label: intl.formatMessage({id: 'userLoginName'}) + ":",
  151. valueName: "username",
  152. disabled: true,
  153. form: formik
  154. })}
  155. </Grid>
  156. <Grid item xs={12} sm={12} md={12} lg={4}>
  157. {FieldUtils.getTextField({
  158. label: intl.formatMessage({id: 'userEnglishName'}) + ":",
  159. valueName: "enName",
  160. disabled: true,
  161. form: formik
  162. })}
  163. </Grid>
  164. <Grid item xs={12} sm={12} md={12} lg={4}>
  165. {FieldUtils.getTextField({
  166. label: intl.formatMessage({id: 'userChineseName'}) + ":",
  167. valueName: "chName",
  168. disabled: true,
  169. form: formik
  170. })}
  171. </Grid>
  172. <Grid item xs={12} sm={12} md={12} lg={4}>
  173. {FieldUtils.getComboField({
  174. label: intl.formatMessage({id: 'idType'}) + ":",
  175. valueName: "idDocType",
  176. disabled: true,
  177. dataList: ComboData.idDocType,
  178. filterOptions: (options) => options,
  179. getOptionLabel: (item) => item ? typeof item === 'string' ? item : (item["type"] ? item["type"] + "-" + item["label"] : "") : "",
  180. onInputChange: (event, newValue, setInputValue) => {
  181. if (newValue == null) {
  182. setInputValue("");
  183. }
  184. let _val = newValue.split("-");
  185. if (_val[0]) {
  186. setInputValue(_val[0]);
  187. }
  188. },
  189. onChange: (event, newValue) => {
  190. if (newValue == null) {
  191. formik.setFieldValue("idDocType", "");
  192. return;
  193. }
  194. formik.setFieldValue("idDocType", newValue.type);
  195. },
  196. form: formik
  197. })}
  198. </Grid>
  199. <Grid xs={12} sm={12} md={12} lg={4}>
  200. <Grid container alignItems={"center"} sx={{mb:2}}>
  201. <Grid item xs={12} sm={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  202. <Typography variant="h5">
  203. <FormattedMessage id="idNo" />:
  204. </Typography>
  205. </Grid>
  206. <Grid item xs={12} sm={12} md={9} lg={6}>
  207. <Grid container>
  208. {formik.values.idDocType === "HKID" ?
  209. <>
  210. <Grid item xs={6} sm={6} md={6} lg={7.5} sx={{mr:1}}>
  211. {FieldUtils.initField({
  212. valueName: "identification",
  213. disabled: true,
  214. form: formik,
  215. placeholder: intl.formatMessage({id: 'idDocNumber'}),
  216. inputProps: {
  217. maxLength: 7,
  218. onKeyDown: (e) => {
  219. if (e.key === 'Enter') {
  220. e.preventDefault();
  221. }
  222. },
  223. }
  224. })}
  225. </Grid>
  226. <Grid item xs={2} sm={2} md={2} lg={2}>
  227. {FieldUtils.initField({
  228. valueName: "checkDigit",
  229. disabled: true,
  230. form: formik
  231. })}
  232. </Grid>
  233. </> :
  234. <Grid item xs={12} sm={6} md={6} lg={12}>
  235. {FieldUtils.initField({
  236. valueName: "identification",
  237. disabled: true,
  238. form: formik
  239. })}
  240. </Grid>
  241. }
  242. </Grid>
  243. </Grid>
  244. </Grid>
  245. </Grid>
  246. <Grid item xs={12} sm={12} md={12} lg={4}>
  247. {FieldUtils.getPhoneField({
  248. label: intl.formatMessage({id: 'userContactNumber'}) + ":",
  249. valueName: {
  250. code: "tel_countryCode",
  251. num: "phoneNumber"
  252. },
  253. disabled: (!editMode),
  254. form: formik
  255. })}
  256. </Grid>
  257. <Grid item xs={12} sm={12} md={12} lg={4}>
  258. {FieldUtils.getComboField({
  259. label: intl.formatMessage({id: 'country'}) + ":",
  260. valueName: "country",
  261. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  262. dataList: ComboData.country,
  263. disabled: (!editMode),
  264. form: formik
  265. })}
  266. </Grid>
  267. <Grid item xs={12} sm={12} md={12} lg={4}>
  268. {FieldUtils.getTextField({
  269. label: intl.formatMessage({id: 'userContactEmail'}) + ":",
  270. valueName: "emailAddress",
  271. disabled: true,
  272. form: formik
  273. })}
  274. </Grid>
  275. <Grid item xs={12} sm={12} md={12} lg={4}>
  276. {FieldUtils.getPhoneField({
  277. label: intl.formatMessage({id: 'userFaxNumber'}) + ":",
  278. valueName: {
  279. code: "fax_countryCode",
  280. num: "faxNumber"
  281. },
  282. disabled: (!editMode),
  283. form: formik
  284. })}
  285. </Grid>
  286. <Grid item xs={12} sm={12} md={12} lg={4}>
  287. {FieldUtils.getAddressField({
  288. label: intl.formatMessage({id: 'userAddress'}) + ":",
  289. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  290. disabled: (!editMode),
  291. form: formik
  292. })}
  293. </Grid>
  294. <Grid item xs={12} sm={12} md={12} lg={4}>
  295. {FieldUtils.getComboField({
  296. label: intl.formatMessage({id: 'district'}) + ":",
  297. valueName: "district",
  298. dataList: ComboData.district,
  299. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  300. disabled: (!editMode),
  301. form: formik
  302. })}
  303. </Grid>
  304. </Grid>
  305. </Grid>
  306. </form>
  307. }
  308. </MainCard>
  309. );
  310. };
  311. export default UserInformationCard_Individual_Pub;