Skip to content

Commit 879720b

Browse files
committed
Code refactor
1 parent b8c5f12 commit 879720b

File tree

1 file changed

+11
-8
lines changed
  • Track 4_ReactJS_Web Development/Project/Frontend/hrc-dashboard/src/components/navigation/Forms

1 file changed

+11
-8
lines changed

Track 4_ReactJS_Web Development/Project/Frontend/hrc-dashboard/src/components/navigation/Forms/AnalyticsForm.jsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import preparePieChart from '../../../utils/analytics/preparePieChart';
2020
import getAnalyticsData from '../../../utils/api/getAnalyticsData';
2121

2222
function AnalyticsForm({ setOpened, setAnalyticsButtonDisabled }) {
23+
// Copy defaultTableSchema to a variable
24+
const tableSchema = { ...defaultTableSchema };
25+
2326
const form = useForm({
2427
initialValues: { ...defaultTableSchema },
2528
validate: {},
@@ -38,18 +41,18 @@ function AnalyticsForm({ setOpened, setAnalyticsButtonDisabled }) {
3841
formInputFields.forEach((field) => {
3942
const fieldValue = form.getInputProps(field.htmlFor)?.value || '';
4043
// If fieldValue is null or undefined, store null
41-
defaultTableSchema[field.htmlFor] = fieldValue;
44+
tableSchema[field.htmlFor] = fieldValue;
4245
});
4346

4447
// Loop through formDateFields
4548
formDateFields.forEach((field) => {
4649
if (field.type === 'db_date') {
47-
defaultTableSchema[field.htmlFor] = convertDateToDBFormat(values[field.htmlFor.toString()]);
50+
tableSchema[field.htmlFor] = convertDateToDBFormat(values[field.htmlFor.toString()]);
4851
}
4952
});
5053

5154
try {
52-
// Submit defaultTableSchema to the database
55+
// Submit tableSchema to the database
5356
/*
5457
Successful data submission example
5558
0: {rowsAffected: 1}
@@ -59,13 +62,13 @@ function AnalyticsForm({ setOpened, setAnalyticsButtonDisabled }) {
5962
*/
6063

6164
const payload = {
62-
clear_date: [defaultTableSchema.clear_date_start, defaultTableSchema.clear_date_end],
63-
due_in_date: [defaultTableSchema.due_in_date_start, defaultTableSchema.due_in_date_end],
65+
clear_date: [tableSchema.clear_date_start, tableSchema.clear_date_end],
66+
due_in_date: [tableSchema.due_in_date_start, tableSchema.due_in_date_end],
6467
baseline_create_date: [
65-
defaultTableSchema.baseline_create_date_start,
66-
defaultTableSchema.baseline_create_date_end,
68+
tableSchema.baseline_create_date_start,
69+
tableSchema.baseline_create_date_end,
6770
],
68-
invoice_currency: defaultTableSchema.invoice_currency,
71+
invoice_currency: tableSchema.invoice_currency,
6972
};
7073

7174
// Enable the submit button

0 commit comments

Comments
 (0)