fix form logic

This commit is contained in:
rizky 2024-07-24 01:01:07 -07:00
parent 36ece9ec6d
commit acf29ce20e
5 changed files with 39 additions and 15 deletions

View File

@ -57,6 +57,7 @@ export const Form: FC<FMProps> = (props) => {
field: null, field: null,
}, },
has_fields_container: null as any, has_fields_container: null as any,
is_newly_created: false
}); });
const form_inner_ref = useRef<HTMLDivElement>(null); const form_inner_ref = useRef<HTMLDivElement>(null);

View File

@ -157,7 +157,11 @@ ${
...record, ...record,
}, },
}); });
if (res) form.id = res.id;
if (res) {
form.id = res.id;
fm.is_newly_created = true;
}
} }
if (has_many.length) { if (has_many.length) {

View File

@ -30,7 +30,7 @@ export const set_value = ({
${pk}: selected[0], ${pk}: selected[0],
}, },
}; };
} else { } else if (fm.data["${pk}"]) {
fm.data[name] = { fm.data[name] = {
disconnect: true, disconnect: true,
}; };

View File

@ -155,6 +155,7 @@ export type FMInternal = {
field: any; field: any;
}; };
has_fields_container: boolean; has_fields_container: boolean;
is_newly_created: boolean;
}; };
export type FMLocal = FMInternal & { render: () => void }; export type FMLocal = FMInternal & { render: () => void };

View File

@ -83,6 +83,22 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
fm.internal.reload.done.map((e) => e()); fm.internal.reload.done.map((e) => e());
setTimeout(() => { setTimeout(() => {
toast.dismiss(); toast.dismiss();
if (fm.is_newly_created) {
fm.is_newly_created = false;
toast.success(
<div className="c-flex c-text-green-700 c-items-center">
<Check className="c-h-4 c-w-4 c-mr-1 " />
Saved
</div>,
{
className: css`
background: #e4ffed;
border: 2px solid green;
`,
}
);
}
}, 100); }, 100);
fm.status = "ready"; fm.status = "ready";
@ -179,6 +195,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
} }
); );
} else { } else {
if (!fm.is_newly_created) {
toast.success( toast.success(
<div className="c-flex c-text-green-700 c-items-center"> <div className="c-flex c-text-green-700 c-items-center">
<Check className="c-h-4 c-w-4 c-mr-1 " /> <Check className="c-h-4 c-w-4 c-mr-1 " />
@ -192,6 +209,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
} }
); );
} }
}
}, 100); }, 100);
} }
} }