Skip to content

Commit

Permalink
feat: use onPromiseClick
Browse files Browse the repository at this point in the history
  • Loading branch information
greg6775 committed Jan 21, 2024
1 parent b1ff331 commit b63e10f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions pages/admin/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const ApproveDialog = SheetDialog(sheetStack, "Approve Drop",
: Empty()).asRefComponent()),
Spacer(),
Button("Cancel").setStyle(ButtonStyle.Secondary).onClick(() => ApproveDialog.close()),
Button("Submit").onClick(async () => {
Button("Submit").onPromiseClick(async () => {
const { data, error, validate } = Validate(
dialogState,
zod.object({
Expand All @@ -95,7 +95,10 @@ export const ApproveDialog = SheetDialog(sheetStack, "Approve Drop",
);

validate();
if (error.getValue()) return data.validationState = error.getValue();
if (error.getValue()) {
data.validationState = error.getValue();
return;
};

await API.music.id(drop._id).review.post({
title: dropPatternMatching(reviewTexts.APPROVED.header, drop),
Expand Down Expand Up @@ -207,7 +210,7 @@ export const DeclineDialog = SheetDialog(sheetStack, "Decline Drop",
: Empty()).asRefComponent()),
Spacer(),
Button("Cancel").setStyle(ButtonStyle.Secondary).onClick(() => DeclineDialog.close()),
Button("Submit").onClick(async () => {
Button("Submit").onPromiseClick(async () => {
const { error, validate } = Validate(
rejectState,
zod.object({
Expand All @@ -216,7 +219,10 @@ export const DeclineDialog = SheetDialog(sheetStack, "Decline Drop",
);

validate();
if (error.getValue()) return dialogState.validationState = error.getValue();
if (error.getValue()) {
dialogState.validationState = error.getValue();
return;
}

const reason = <ReviewResponse[]>rejectState.respones;

Expand Down
4 changes: 2 additions & 2 deletions pages/admin/views/entryReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const changeTypeDialog = SheetDialog(sheetStack, "Change Drop Type",
DropDownInput("Change Type", Object.values(DropType)).sync(changeState, "type"),
Horizontal(
Spacer(),
Button("Change").onClick(() => {
API.music.id(changeState.drop!._id).type.post(changeState.type!);
Button("Change").onPromiseClick(async () => {
await API.music.id(changeState.drop!._id).type.post(changeState.type!);
changeTypeDialog.close();
})
)
Expand Down

0 comments on commit b63e10f

Please sign in to comment.