Skip to content

Commit

Permalink
Prevent opening accordion from triggering server requests if previous…
Browse files Browse the repository at this point in the history
…ly collapsed
  • Loading branch information
samau3 committed Aug 28, 2024
1 parent a291390 commit 301af9c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions client/src/pages/patients/patients.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function Patients() {
*/
async function submitPatient(values) {
setLoading(true);
console.log(values);

const {
patientData,
contactData,
Expand Down Expand Up @@ -161,14 +161,14 @@ export default function Patients() {
throw new Error('Failed to create patient');
}
} catch (err) {
console.log(err);
console.error(err);
notifications.show({
title: 'Error',
message: err.message,
color: 'red',
});
} finally {
console.log('Finished');

setLoading(false);
}
}
Expand All @@ -178,14 +178,17 @@ export default function Patients() {
* @param {string} value
*/
async function handleAccordionChange(value) {
console.log(value, openedSection);
// console.log(form.getValues()[openedSection]);
if (!openedSection) {
setOpenedSection(value)
return;
}

let errorFieldCount = 0;
for (const field in form.getValues()[openedSection]) {
form.validateField(`${openedSection}.${field}`);
form.isValid(`${openedSection}.${field}`) ? null : errorFieldCount++;
}
console.log(errorFieldCount);

if (errorFieldCount === 0) {
setOpenedSection(value);

Expand Down Expand Up @@ -215,7 +218,7 @@ export default function Patients() {
throw new Error('Failed to register patient');
}
} catch (err) {
console.log(err);
console.error(err);
notifications.show({
title: 'Error',
message: err.message,
Expand All @@ -227,7 +230,7 @@ export default function Patients() {
const res = await updatePatient({
[openedSection]: form.getValues()[openedSection],
});
console.log(await res.json());

if (res.status === StatusCodes.OK) {
notifications.show({
title: 'Success',
Expand All @@ -251,8 +254,6 @@ export default function Patients() {
}
}

// Validate a form field: form.validateField('user.firstName');

/**
*
* @param {object} errors
Expand Down

0 comments on commit 301af9c

Please sign in to comment.