Skip to content

Commit

Permalink
fix(dash): sanitize custom field (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro authored Mar 30, 2022
1 parent 7ff8e02 commit 21ea43c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dashboard/src/components/TableCustomFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const newField = () => ({

const getValueFromType = (type) => typeOptions.find((opt) => opt.value === type);

const sanitizeFields = (field) => {
const sanitizedField = {};
for (const key of Object.keys(field)) {
if (![undefined, null].includes(field[key])) sanitizedField[key] = field[key];
}
return sanitizedField;
};

const TableCustomFields = ({ data, customFields, showHealthcareProfessionnalColumn = false }) => {
const [isSubmitting, setIsSubmitting] = useState(false);
const [mutableData, setMutableData] = useState(data);
Expand Down Expand Up @@ -65,16 +73,8 @@ const TableCustomFields = ({ data, customFields, showHealthcareProfessionnalColu
};

const handleSubmit = async (newData) => {
if (!newData)
newData = mutableData
.filter((field) => !!field.label.length)
.map((field) => {
const sanitizedField = {};
for (const key of Object.keys(field)) {
if (![undefined, null].includes(field[key])) sanitizedField[key] = field[key];
}
return sanitizedField;
});
if (!newData) newData = mutableData.filter((field) => !!field.label.length);
newData = newData.map(sanitizeFields);
setIsSubmitting(true);
try {
const response = await API.put({
Expand Down

0 comments on commit 21ea43c

Please sign in to comment.