Browse Source

Merge pull request 'dev-wahyun' (#94) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-frontend#94
pull/1/head
farhantock 7 months ago
parent
commit
4bfa81891a
  1. 11
      src/views/SimproV2/ResourceWorker/DialogForm.js
  2. 62
      src/views/SimproV2/ResourceWorker/index.js

11
src/views/SimproV2/ResourceWorker/DialogForm.js

@ -3,7 +3,7 @@ import {
Modal, ModalHeader, ModalBody, ModalFooter, Modal, ModalHeader, ModalBody, ModalFooter,
Button, Form, FormGroup, Label, Input, Col, Row Button, Form, FormGroup, Label, Input, Col, Row
} from 'reactstrap'; } from 'reactstrap';
import { DatePicker, Tooltip, Select, Input as InputAntd } from 'antd'; import { DatePicker, Select, Input as InputAntd } from 'antd';
import moment from 'moment'; import moment from 'moment';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import { formatNumber } from '../../../const/CustomFunc' import { formatNumber } from '../../../const/CustomFunc'
@ -223,7 +223,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email); return emailRegex.test(email);
}; };
const renderForm = () => { const renderFormAddUser = () => {
return ( return (
<Form> <Form>
<Row> <Row>
@ -383,7 +383,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
) )
} }
const renderForm2 = () => { const renderFormSetUser = () => {
return ( return (
<Form> <Form>
<Row> <Row>
@ -420,19 +420,16 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
</Form> </Form>
) )
} }
return ( return (
<> <>
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> <Modal size="lg" isOpen={openDialog} toggle={toggleDialog}>
<ModalHeader className="capitalize" toggle={closeDialog}>{typeDialog == "Save" ? `Add` : "Edit"} {t('hr')}</ModalHeader> <ModalHeader className="capitalize" toggle={closeDialog}>{typeDialog == "Save" ? `Add` : "Edit"} {t('hr')}</ModalHeader>
<ModalBody> <ModalBody>
{typeDialog !== "Set" ? renderForm() : renderForm2()} {typeDialog !== "Set" ? renderFormAddUser() : renderFormSetUser()}
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button color="primary" onClick={() => handleSave()}>{typeDialog}</Button>{' '} <Button color="primary" onClick={() => handleSave()}>{typeDialog}</Button>{' '}

62
src/views/SimproV2/ResourceWorker/index.js

@ -460,18 +460,29 @@ const ResourceWorker = ({ params, ...props }) => {
} }
const saveUser = async (data) => { const saveUser = async (data) => {
const formData = data try {
const result = await axios.post(USER_ADD, formData, HEADER) const result = await axios.post(USER_ADD, data, HEADER);
.then(res => res) if (result.data.code === 200) {
.catch((error) => error.response); getDataUser();
NotificationManager.success(`Data resource berhasil ditambah`, 'Success!!');
if (result && result.data && result.data.code === 200) { } else {
getDataUser(); NotificationManager.error(result.data.message, 'Failed!!');
NotificationManager.success(`Data resource berhasil ditambah`, 'Success!!'); }
} else { } catch (error) {
NotificationManager.error(`${result.data.message}`, 'Failed!!'); if (error.response && error.response.data) {
const errors = error.response.data;
setOpenDialog(true);
for (const [field, messages] of Object.entries(errors)) {
messages.forEach(message => {
NotificationManager.error(message, `Error validation`);
});
}
} else {
setOpenDialog(true);
NotificationManager.error('Internal server error', 'Error!!');
}
} }
} };
const saveUserShift = async (data) => { const saveUserShift = async (data) => {
const formData = data const formData = data
@ -488,19 +499,32 @@ const ResourceWorker = ({ params, ...props }) => {
} }
const editUser = async (data) => { const editUser = async (data) => {
let urlEdit = USER_EDIT(data.id) let urlEdit = USER_EDIT(data.id)
const formData = data const formData = data
const result = await axios.put(urlEdit, formData, HEADER) try {
const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
if (result && result.data && result.data.code === 200) { getDataUser();
getDataUser(); NotificationManager.success(`Data resource berhasil diedit`, 'Success!!');
NotificationManager.success(`Data resource berhasil diedit`, 'Success!!'); } else {
} else { NotificationManager.error(`${result.data.message}`, `Failed!!`);
NotificationManager.error(`${result.data.message}`, `Failed!!`); }
} catch (error) {
if (error.response && error.response.data) {
const errors = error.response.data;
setOpenDialog(true);
for (const [field, messages] of Object.entries(errors)) {
messages.forEach(message => {
NotificationManager.error(message, `Error validation`);
});
}
} else {
setOpenDialog(true);
NotificationManager.error('Internal server error', 'Error!!');
}
} }
} }

Loading…
Cancel
Save