Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

371 lignes
17 KiB

  1. // material-ui
  2. import {
  3. Grid, Button,
  4. // Checkbox, FormControlLabel,
  5. Typography,
  6. Dialog, DialogTitle, DialogContent, DialogActions,
  7. } from '@mui/material';
  8. // import { FormControlLabel } from '@material-ui/core';
  9. import MainCard from "components/MainCard";
  10. import * as React from "react";
  11. import { useFormik } from 'formik';
  12. import * as yup from 'yup';
  13. import { useEffect, useState } from "react";
  14. import * as HttpUtils from 'utils/HttpUtils';
  15. import * as UrlUtils from "utils/ApiPathConst";
  16. import * as FieldUtils from "utils/FieldUtils";
  17. import * as ComboData from "utils/ComboData";
  18. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  19. import Loadable from 'components/Loadable';
  20. import { lazy } from 'react';
  21. import { notifySaveSuccess } from 'utils/CommonFunction';
  22. import {FormattedMessage, useIntl} from "react-intl";
  23. import {PNSPS_BUTTON_THEME} from "themes/buttonConst";
  24. import {ThemeProvider} from "@emotion/react";
  25. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  26. const OrganizationPubCard = ({ userData, loadDataFun, id, setEditModeFun }) => {
  27. const intl = useIntl();
  28. const [creditorConfirmPopUp, setCreditorConfirmPopUp] = React.useState(false);
  29. const [nonCreditorConfirmPopUp, setNonCreditorConfirmPopUp] = React.useState(false);
  30. const [currentUserData, setCurrentUserData] = useState({});
  31. const [editMode, setEditMode] = useState(false);
  32. const [createMode, setCreateMode] = useState(false);
  33. const [onReady, setOnReady] = useState(false);
  34. useEffect(() => {
  35. //if state data are ready and assign to different field
  36. // console.log(currentApplicationDetailData)
  37. if (Object.keys(currentUserData).length > 0) {
  38. setOnReady(true);
  39. }
  40. }, [currentUserData]);
  41. function displayErrorMsg(errorMsg) {
  42. return <Typography variant="errorMessage1">{errorMsg}</Typography>
  43. }
  44. const formik = useFormik({
  45. enableReinitialize: true,
  46. initialValues: currentUserData,
  47. validationSchema: yup.object().shape({
  48. addressLine1: yup.string().max(40).required(displayErrorMsg(intl.formatMessage({id: 'validateAddressLine1'}))),
  49. addressLine2: yup.string().max(40, displayErrorMsg(intl.formatMessage({id: 'noMoreThen255Words'}))),
  50. addressLine3: yup.string().max(40, displayErrorMsg(intl.formatMessage({id: 'noMoreThen255Words'}))),
  51. tel_countryCode: yup.string().min(3, displayErrorMsg(intl.formatMessage({id: 'requireDialingCode'}))),
  52. phoneNumber: yup.string().min(8, displayErrorMsg(intl.formatMessage({id: 'requiredValidNumber'}))).required(displayErrorMsg(intl.formatMessage({id: 'requireContactNumber'}))),
  53. }),
  54. onSubmit: vaule => {
  55. console.log(vaule)
  56. HttpUtils.post({
  57. url: UrlUtils.POST_PUB_ORG_SAVE_PATH,
  58. params: {
  59. contactPerson: vaule.contactPerson,
  60. contactTel: {
  61. countryCode: vaule.tel_countryCode,
  62. phoneNumber: vaule.phoneNumber
  63. },
  64. addressTemp: {
  65. country: vaule.country.id,
  66. district: vaule.district.id,
  67. addressLine1: vaule.addressLine1,
  68. addressLine2: vaule.addressLine2,
  69. addressLine3: vaule.addressLine3,
  70. },
  71. //creditor: vaule.creditor,
  72. },
  73. onSuccess: function () {
  74. notifySaveSuccess()
  75. loadDataFun();
  76. setEditMode(false);
  77. }
  78. });
  79. }
  80. });
  81. useEffect(()=>{
  82. setEditModeFun(editMode);
  83. },[editMode]);
  84. useEffect(() => {
  85. if (Object.keys(userData).length > 0) {
  86. setCreateMode(id <= 0);
  87. setEditMode(id <= 0);
  88. setCurrentUserData(userData);
  89. }
  90. }, [userData]);
  91. // useEffect(() => {
  92. // if (Object.keys(userData).length > 0) {
  93. // if(userData.creditor === undefined||userData.creditor === null){
  94. // userData.creditor = false
  95. // }
  96. // setCurrentUserData(userData);
  97. // }
  98. // }, []);
  99. const onEditClick = () => {
  100. setEditMode(true);
  101. };
  102. return (
  103. <MainCard elevation={0}
  104. border={false}
  105. content={false}
  106. >
  107. <form onSubmit={formik.handleSubmit} style={{ padding: 24 }}>
  108. {/*top*/}
  109. <Grid item s={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  110. <Grid container maxWidth justifyContent="flex-start">
  111. {editMode ?
  112. <>
  113. {createMode ?
  114. <>
  115. <Grid item sx={{ ml: 0, mr: 3 }}>
  116. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  117. <Button
  118. variant="contained"
  119. type="submit"
  120. color="success"
  121. >
  122. <FormattedMessage id="create" />
  123. </Button>
  124. </ThemeProvider>
  125. </Grid>
  126. </> :
  127. <>
  128. <Grid item sx={{ ml: 0, mr: 3 }}>
  129. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  130. <Button
  131. variant="contained"
  132. color="cancel"
  133. onClick={loadDataFun}
  134. >
  135. <FormattedMessage id="resetAndBack" />
  136. </Button>
  137. </ThemeProvider>
  138. </Grid>
  139. <Grid item sx={{ ml: 3, mr: 3 }}>
  140. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  141. <Button
  142. variant="contained"
  143. type="submit"
  144. color="success"
  145. >
  146. <FormattedMessage id="save" />
  147. </Button>
  148. </ThemeProvider>
  149. </Grid>
  150. </>
  151. }
  152. </>
  153. :
  154. <>
  155. <Grid item sx={{ ml: 0, mr: 3 }}>
  156. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  157. <Button
  158. variant="contained"
  159. onClick={onEditClick}
  160. color="success"
  161. >
  162. < FormattedMessage id="edit" />
  163. </Button>
  164. </ThemeProvider>
  165. </Grid>
  166. </>
  167. }
  168. </Grid>
  169. </Grid>
  170. {/*top*/}
  171. {!onReady ?
  172. <LoadingComponent />
  173. :
  174. <Grid container spacing={1}>
  175. <Grid item xs={12}>
  176. <Typography variant="h4" sx={{ mb: 2, mr: 3, borderBottom: "1px solid black" }}>
  177. <FormattedMessage id="organizationDetails" />
  178. </Typography>
  179. </Grid>
  180. <Grid item lg={4} >
  181. {FieldUtils.getTextField({
  182. label: intl.formatMessage({id: 'brNo'}) + ":",
  183. valueName: "brNo",
  184. disabled: true,
  185. form: formik
  186. })}
  187. </Grid>
  188. <Grid item lg={4} >
  189. {FieldUtils.getTextField({
  190. label: intl.formatMessage({id: 'creditorAccount'}) + ":",
  191. valueName: "creditor",
  192. disabled: true,
  193. form: formik
  194. })}
  195. {/* <FormControlLabel
  196. control={<Checkbox checked={formik.values.creditor} />}
  197. label="is Creditor"
  198. name="creditor"
  199. onChange={() => {
  200. formik.setFieldValue("creditor", !formik.values.creditor);
  201. }}
  202. disabled={true}
  203. //disabled={!editMode && !createMode}
  204. /> */}
  205. </Grid>
  206. <Grid item lg={4} ></Grid>
  207. <Grid item lg={4} >
  208. {FieldUtils.getTextField({
  209. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'nameEng'}) + ":"),
  210. valueName: "enCompanyName",
  211. disabled: true,
  212. form: formik
  213. })}
  214. </Grid>
  215. <Grid item lg={4} >
  216. {FieldUtils.getTextField({
  217. label: intl.formatMessage({id: 'nameChi'}) + ":",
  218. valueName: "chCompanyName",
  219. disabled: true,
  220. form: formik
  221. })}
  222. </Grid>
  223. <Grid item lg={4} >
  224. {FieldUtils.getDateField({
  225. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'expiryDate'}) + ":"),
  226. valueName: "brExpiryDate",
  227. disabled: true,
  228. form: formik
  229. })}
  230. </Grid>
  231. <Grid item lg={4} >
  232. {FieldUtils.getTextField({
  233. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'contactPerson'}) + ":"),
  234. valueName: "contactPerson",
  235. disabled: (!editMode && !createMode),
  236. form: formik
  237. })}
  238. </Grid>
  239. <Grid item lg={4} >
  240. {FieldUtils.getPhoneField({
  241. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'userContactNumber'}) + ":"),
  242. valueName: {
  243. code: "tel_countryCode",
  244. num: "phoneNumber"
  245. },
  246. disabled: (!editMode && !createMode),
  247. form: formik
  248. })}
  249. </Grid>
  250. <Grid item lg={4} >
  251. {FieldUtils.getPhoneField({
  252. label: intl.formatMessage({id: 'contactFaxNumber'}) + ":",
  253. valueName: {
  254. code: "fax_countryCode",
  255. num: "faxNumber"
  256. },
  257. disabled: true,
  258. form: formik
  259. })}
  260. </Grid>
  261. <Grid item lg={4} >
  262. {FieldUtils.getComboField({
  263. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'country'}) + ":"),
  264. valueName: "country",
  265. disabled: (!editMode && !createMode),
  266. dataList: ComboData.country,
  267. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  268. form: formik
  269. })}
  270. </Grid>
  271. <Grid item lg={4} >
  272. {FieldUtils.getComboField({
  273. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'district'}) + ":"),
  274. valueName: "district",
  275. disabled: (!editMode && !createMode),
  276. dataList: ComboData.district,
  277. getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "",
  278. form: formik
  279. })}
  280. </Grid>
  281. <Grid item lg={4} >
  282. {FieldUtils.getAddressField({
  283. label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'formAddress'}) + ":"),
  284. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  285. disabled: (!editMode && !createMode),
  286. form: formik
  287. })}
  288. </Grid>
  289. <Grid item lg={12} ></Grid>
  290. </Grid>
  291. }
  292. </form>
  293. <div>
  294. <Dialog
  295. open={creditorConfirmPopUp}
  296. onClose={() => setCreditorConfirmPopUp(false)}
  297. PaperProps={{
  298. sx: {
  299. minWidth: '40vw',
  300. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  301. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  302. }
  303. }}
  304. >
  305. <DialogTitle><Typography variant="h3">Confirm</Typography></DialogTitle>
  306. <DialogContent style={{ display: 'flex', }}>
  307. <Typography variant="h4" style={{ padding: '16px' }}>Are you sure mark as Creditor?</Typography>
  308. </DialogContent>
  309. <DialogActions>
  310. <Button onClick={() => setCreditorConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  311. <Button onClick={() => markAsCreditor()}><Typography variant="h5">Confirm</Typography></Button>
  312. </DialogActions>
  313. </Dialog>
  314. </div>
  315. <div>
  316. <Dialog
  317. open={nonCreditorConfirmPopUp}
  318. onClose={() => setNonCreditorConfirmPopUp(false)}
  319. PaperProps={{
  320. sx: {
  321. minWidth: '40vw',
  322. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  323. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  324. }
  325. }}
  326. >
  327. <DialogTitle><Typography variant="h3">Confirm</Typography></DialogTitle>
  328. <DialogContent style={{ display: 'flex', }}>
  329. <Typography variant="h4" style={{ padding: '16px' }}>Are you sure mark as Non-Creditor?</Typography>
  330. </DialogContent>
  331. <DialogActions>
  332. <Button onClick={() => setNonCreditorConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  333. <Button onClick={() => markAsNonCreditor()}><Typography variant="h5">Confirm</Typography></Button>
  334. </DialogActions>
  335. </Dialog>
  336. </div>
  337. </MainCard>
  338. );
  339. };
  340. export default OrganizationPubCard;