- Add mailbox persistence mapper for domain object mapping. - Create Sequelize repository for mailbox data access. - Define common mailbox schemas and types for validation. - Implement mailbox API for frontend communication. - Develop mailbox form component for creating and editing mailboxes. - Add internationalization support for mailbox labels and messages. - Create mailbox use form for managing mailbox usage periods. - Build mailboxes page to display and manage mailboxes and their usage.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { z } from "zod/v4";
|
|
|
|
import {
|
|
type MailboxInput,
|
|
type MailboxUseInput,
|
|
MailboxesResponseSchema,
|
|
} from "../../common/mailboxes";
|
|
|
|
import { MailApiError } from "./mail-api";
|
|
export const mailboxKeys = { company: (id: string) => ["mailboxes", id] };
|
|
export const mailboxApi = {
|
|
async request(
|
|
companyId: string,
|
|
values?: MailboxInput | MailboxUseInput,
|
|
token?: string,
|
|
id?: string
|
|
) {
|
|
const suffix = values && "mailboxId" in values ? "/uses" : "";
|
|
const response = await fetch(
|
|
`/api/mailboxes/${companyId}${suffix}${id ? `/${id}/update` : ""}`,
|
|
{
|
|
method: values ? "POST" : "GET",
|
|
credentials: "same-origin",
|
|
headers: values ? { "content-type": "application/json", "x-csrf-token": token ?? "" } : {},
|
|
...(values ? { body: JSON.stringify({ values }) } : {}),
|
|
}
|
|
);
|
|
const json: unknown = await response.json();
|
|
if (!response.ok) {
|
|
const parsed = z.object({ code: z.string() }).safeParse(json);
|
|
throw new MailApiError(parsed.success ? parsed.data.code : "INTERNAL_ERROR");
|
|
}
|
|
return MailboxesResponseSchema.parse(json);
|
|
},
|
|
};
|