fix form logic
This commit is contained in:
parent
36ece9ec6d
commit
acf29ce20e
|
|
@ -57,6 +57,7 @@ export const Form: FC<FMProps> = (props) => {
|
|||
field: null,
|
||||
},
|
||||
has_fields_container: null as any,
|
||||
is_newly_created: false
|
||||
});
|
||||
const form_inner_ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,11 @@ ${
|
|||
...record,
|
||||
},
|
||||
});
|
||||
if (res) form.id = res.id;
|
||||
|
||||
if (res) {
|
||||
form.id = res.id;
|
||||
fm.is_newly_created = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (has_many.length) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export const set_value = ({
|
|||
${pk}: selected[0],
|
||||
},
|
||||
};
|
||||
} else {
|
||||
} else if (fm.data["${pk}"]) {
|
||||
fm.data[name] = {
|
||||
disconnect: true,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ export type FMInternal = {
|
|||
field: any;
|
||||
};
|
||||
has_fields_container: boolean;
|
||||
is_newly_created: boolean;
|
||||
};
|
||||
export type FMLocal = FMInternal & { render: () => void };
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,22 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
|||
fm.internal.reload.done.map((e) => e());
|
||||
setTimeout(() => {
|
||||
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);
|
||||
|
||||
fm.status = "ready";
|
||||
|
|
@ -179,6 +195,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
|||
}
|
||||
);
|
||||
} else {
|
||||
if (!fm.is_newly_created) {
|
||||
toast.success(
|
||||
<div className="c-flex c-text-green-700 c-items-center">
|
||||
<Check className="c-h-4 c-w-4 c-mr-1 " />
|
||||
|
|
@ -192,6 +209,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
|||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue