Add pending inputs as a new Keyword

Ensures that any Keywords that were intended to be added are not lost
This commit is contained in:
CorreyL
2024-01-18 19:45:29 -08:00
parent 390f274d06
commit ac322a9bd4

View File

@ -31,6 +31,7 @@ type Props<T extends SectionItem> = {
id: DialogName;
form: UseFormReturn<T>;
defaultValues: T;
pendingKeyword?: string;
children: React.ReactNode;
};
@ -38,6 +39,7 @@ export const SectionDialog = <T extends SectionItem>({
id,
form,
defaultValues,
pendingKeyword,
children,
}: Props<T>) => {
const { isOpen, mode, close, payload } = useDialog<T>(id);
@ -61,6 +63,9 @@ export const SectionDialog = <T extends SectionItem>({
if (!section) return;
if (isCreate || isDuplicate) {
if (pendingKeyword && values.keywords) {
values.keywords.push(pendingKeyword);
}
setValue(
`sections.${id}.items`,
produce(section.items, (draft: T[]): void => {
@ -72,6 +77,10 @@ export const SectionDialog = <T extends SectionItem>({
if (isUpdate) {
if (!payload.item?.id) return;
if (pendingKeyword && values.keywords) {
values.keywords.push(pendingKeyword);
}
setValue(
`sections.${id}.items`,
produce(section.items, (draft: T[]): void => {