refactor admin crud popups
All checks were successful
deploy / build-and-deploy (push) Successful in 23s

This commit is contained in:
2025-05-21 17:22:20 +02:00
parent 8b18623232
commit e47268111a
46 changed files with 889 additions and 1041 deletions

View File

@@ -0,0 +1,48 @@
import { type ActionReturnType, actions } from 'astro:actions';
import { writable } from 'svelte/store';
import { actionErrorPopup } from '@util/action.ts';
// types
export type BlockedUsers = Exclude<ActionReturnType<typeof actions.user.blocked>['data'], undefined>['blocked'];
export type BlockedUser = BlockedUsers[0];
// state
export const blockedUsers = writable<BlockedUsers>([]);
// actions
export async function fetchBlockedUsers() {
const { data, error } = await actions.user.blocked();
if (error) {
actionErrorPopup(error);
return;
}
blockedUsers.set(data.blocked);
}
export async function addBlockedUser(blockedUser: BlockedUser) {
const { data, error } = await actions.user.addBlocked(blockedUser);
if (error) {
actionErrorPopup(error);
return;
}
blockedUsers.update((old) => {
old.push(Object.assign(blockedUser, { id: data.id }));
return old;
});
}
export async function editBlockedUser(blockedUser: BlockedUser) {
const { error } = await actions.user.editBlocked(blockedUser);
if (error) {
actionErrorPopup(error);
return;
}
blockedUsers.update((old) => {
const index = old.findIndex((a) => a.id == blockedUser.id);
old[index] = blockedUser;
return old;
});
}