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