refactor: update submit handlers to return boolean for success indication in label and post dialogs
This commit is contained in:
parent
f6eece7071
commit
9b33ea6c7a
@ -30,7 +30,7 @@
|
|||||||
onSubmit: createLabel,
|
onSubmit: createLabel,
|
||||||
}: {
|
}: {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
onSubmit: (params: FormParams) => Promise<void>;
|
onSubmit: (params: FormParams) => Promise<boolean>;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let open = $state(false);
|
let open = $state(false);
|
||||||
@ -62,7 +62,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await createLabel(formData);
|
const isSuccess = await createLabel(formData);
|
||||||
|
if (!isSuccess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
formData = {
|
formData = {
|
||||||
name: '',
|
name: '',
|
||||||
color: '#dddddd',
|
color: '#dddddd',
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
const labelsListedState = $derived($labelsListedStore);
|
const labelsListedState = $derived($labelsListedStore);
|
||||||
const { trigger: loadLabels } = labelsListedStore;
|
const { trigger: loadLabels } = labelsListedStore;
|
||||||
|
|
||||||
async function onCreateLabelDialogSubmit(params: CreateLabelDialogFormParams) {
|
async function onCreateLabelDialogSubmit(params: CreateLabelDialogFormParams): Promise<boolean> {
|
||||||
const colorViewModel = ColorViewModel.fromHex(params.color);
|
const colorViewModel = ColorViewModel.fromHex(params.color);
|
||||||
const color = colorViewModel.toEntity();
|
const color = colorViewModel.toEntity();
|
||||||
|
|
||||||
@ -39,7 +39,10 @@
|
|||||||
toast.error('Failed to create label', {
|
toast.error('Failed to create label', {
|
||||||
description: state.error.message,
|
description: state.error.message,
|
||||||
});
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => loadLabels());
|
onMount(() => loadLabels());
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
onSubmit: createPost,
|
onSubmit: createPost,
|
||||||
}: {
|
}: {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
onSubmit: (params: FormParams) => Promise<void>;
|
onSubmit: (params: FormParams) => Promise<boolean>;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let open = $state(false);
|
let open = $state(false);
|
||||||
@ -50,7 +50,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await createPost(formData);
|
const isSuccess = await createPost(formData);
|
||||||
|
if (!isSuccess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
formData = { semanticId: '', title: '' };
|
formData = { semanticId: '', title: '' };
|
||||||
open = false;
|
open = false;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
const postsListedState = $derived($postsListedStore);
|
const postsListedState = $derived($postsListedStore);
|
||||||
const { trigger: loadPosts } = postsListedStore;
|
const { trigger: loadPosts } = postsListedStore;
|
||||||
|
|
||||||
async function onCreatePostDialogSubmit(params: CreatePostDialogFormParams) {
|
async function onCreatePostDialogSubmit(params: CreatePostDialogFormParams): Promise<boolean> {
|
||||||
const state = await createPost(params);
|
const state = await createPost(params);
|
||||||
|
|
||||||
if (state.isSuccess()) {
|
if (state.isSuccess()) {
|
||||||
@ -32,7 +32,10 @@
|
|||||||
toast.error('Failed to create post', {
|
toast.error('Failed to create post', {
|
||||||
description: state.error.message,
|
description: state.error.message,
|
||||||
});
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => loadPosts({ showUnpublished: true }));
|
onMount(() => loadPosts({ showUnpublished: true }));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user