@@ -49,10 +49,8 @@ const CreateModal = ({ setShowModal, caseData }) => {
|
|||||||
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function saveCaseData() {
|
async function saveCaseData(dataValues) {
|
||||||
const dataValues = validateData();
|
if (isBusy) {
|
||||||
|
|
||||||
if (dataValues === null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsBusy(true);
|
setIsBusy(true);
|
||||||
@@ -90,10 +88,20 @@ const CreateModal = ({ setShowModal, caseData }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCreate = () => {
|
const handleCreateCase = (e) => {
|
||||||
if (!isBusy) {
|
e.preventDefault();
|
||||||
void saveCaseData();
|
const dataValues = validateData();
|
||||||
|
|
||||||
|
if (dataValues === null) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
saveCaseData(dataValues);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
navigate("/dashboard");
|
navigate("/dashboard");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -528,7 +536,7 @@ const CreateModal = ({ setShowModal, caseData }) => {
|
|||||||
<Button
|
<Button
|
||||||
className="primary-button"
|
className="primary-button"
|
||||||
disabled={isBusy}
|
disabled={isBusy}
|
||||||
onClick={handleCreate}
|
onClick={handleCreateCase}
|
||||||
labelText="Save Case"
|
labelText="Save Case"
|
||||||
/>
|
/>
|
||||||
</Modal.Footer>
|
</Modal.Footer>
|
||||||
|
|||||||
@@ -180,7 +180,6 @@ const SignupPage = () => {
|
|||||||
<Row key={`row${j}`}>
|
<Row key={`row${j}`}>
|
||||||
{names.map((name, i) => (
|
{names.map((name, i) => (
|
||||||
<Col key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
<Col key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
||||||
{console.log("data, name", data, name)}
|
|
||||||
<TextInput
|
<TextInput
|
||||||
name={name}
|
name={name}
|
||||||
value={data[name].value}
|
value={data[name].value}
|
||||||
|
|||||||
@@ -96,8 +96,10 @@ export const handleFormDataChange = (e, name, data, fields) => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isFormDataHasErrors = (data) =>
|
export const isFormDataHasErrors = (data) => {
|
||||||
Object.values(data).reduce(
|
console.log("data", data);
|
||||||
|
return Object.values(data).reduce(
|
||||||
(hasErrors, { error }) => hasErrors || error,
|
(hasErrors, { error }) => hasErrors || error,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user