Skip to content

Commit

Permalink
sync ui state fix1
Browse files Browse the repository at this point in the history
  • Loading branch information
armintalaie committed Sep 7, 2024
1 parent 849cfa7 commit 9aefc7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
31 changes: 18 additions & 13 deletions src/app/portal/admin/forms/[id]/submissions/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,16 @@ export function createColumns<TData>(
label: member.display_name || member.email,
}));
return (
<SelectField
options={memberOptions}
field={field}
value={value?.toString()}
submissionId={submissionId}
id={key}
/>
<div>
{value?.toString()}
<SelectField
options={memberOptions}
field={field}
value={value?.toString()}
submissionId={submissionId}
id={key}
/>
</div>
);
}

Expand Down Expand Up @@ -344,10 +347,11 @@ export function SelectField({

const updateField = async (val: any) => {
const prev = selected;
setSelected(val);
updateSubmissionField(submissionId, id, field.config?.tableName, val)
const setVal = val === undefined || val === null || val === "" ? null : val;
setSelected(setVal);
updateSubmissionField(submissionId, id, field.config?.tableName, setVal)
.then(() => {
mergeNewData({ [id]: val }, "id", submissionId);
// mergeNewData({ [id]: val }, "id", submissionId);
toast.success("Field updated successfully");
})
.catch(() => {
Expand Down Expand Up @@ -397,10 +401,11 @@ function TextareaField({
}
const updateField = async (val: string) => {
const prev = text;
setText(val);
updateSubmissionField(submissionId, id, field.config?.tableName, val)
const setVal = val === undefined || val === null || val === "" ? null : val;
setText(setVal);
updateSubmissionField(submissionId, id, field.config?.tableName, setVal)
.then(() => {
mergeNewData({ [id]: val }, "id", submissionId);
mergeNewData({ [id]: setVal }, "id", submissionId);
toast.success("Field updated successfully");
})
.catch(() => {
Expand Down
15 changes: 9 additions & 6 deletions src/components/layouts/formTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ function useRealtimeUpdate({
keyName: string,
key: string,
) {
const newDataUpdate = submissions.map((item) => {
if (item[keyName] === key) {
return { ...item, ...newData };
}
return item;
setSubmissions((prev) => {
return prev.map((item) => {
if (item[keyName] === key) {
// console.log("newData", newData);
// console.log("keyName", keyName);
return { ...item, ...newData };
}
return item;
});
});
setSubmissions(newDataUpdate);
}

useEffect(() => {
Expand Down

0 comments on commit 9aefc7d

Please sign in to comment.