refactor: update submit handlers to return boolean for success indication in label and post dialogs
Some checks failed
Frontend CI / build (push) Failing after 55s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 16s
PR Title Check / pr-title-check (pull_request) Successful in 17s

This commit is contained in:
SquidSpirit 2025-10-15 12:08:17 +08:00
parent f6eece7071
commit 9b33ea6c7a
4 changed files with 20 additions and 6 deletions

View File

@ -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',

View File

@ -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());

View File

@ -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;
}

View File

@ -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 }));