Files
varo-website/src/app/admin/admins/actions.ts
bytedream 60f3f8a096
Some checks failed
deploy / build-and-deploy (push) Failing after 21s
initial commit
2025-05-18 13:16:20 +02:00

42 lines
979 B
TypeScript

import type { Admin } from './types.ts';
import { actions } from 'astro:actions';
import { admins } from './state.ts';
import { actionErrorPopup } from '@util/action.ts';
export async function fetchAdmins() {
const { data, error } = await actions.admin.admins();
if (error) {
actionErrorPopup(error);
return;
}
admins.set(data.admins);
}
export async function addAdmin(admin: Admin & { password: string }) {
const { data, error } = await actions.admin.addAdmin(admin);
if (error) {
actionErrorPopup(error);
return;
}
admins.update((old) => {
old.push(Object.assign(admin, { id: data.id }));
return old;
});
}
export async function editAdmin(admin: Admin & { password: string }) {
const { error } = await actions.admin.editAdmin(admin);
if (error) {
actionErrorPopup(error);
return;
}
admins.update((old) => {
const index = old.findIndex((a) => a.id == admin.id);
old[index] = admin;
return old;
});
}