type FailResponse<T> = {
ok: false;
error: string;
} & T;
type SuccessResponse<T> = {
ok: true;
} & T;
export type DefaultResponse<T = {}, U = {}> =
| SuccessResponse<T>
| FailResponse<U>;
export type NewStatusResponse = DefaultResponse<
{
id: string;
},
{
supportedServers?: string[];
clientServer?: string;
}
>;
return NextResponse.json<NewStatusesResponse>(
{ ok: false, error: "Not logged in" },
{ status: 401 }
);
return NextResponse.json<NewStatusResponse>(
{
ok: false,
error: "BETA_LIMITED_SERVER_ERROR",
supportedServers,
clientServer,
},
{ status: 403 }
);
return NextResponse.json<NewStatusResponse>({ ok: true, id: status.id });
const [submit, { data, isLoading }] = useMutation<
NewStatusResponse,
NewStatusRequest
>("/api/post", "POST");
useEffect(() => {
if (data && data.ok) {
mutate("/api/post");
router.replace(`/post/${data.id}`);
return;
}
if (data && !data.ok && data.error === "BETA_LIMITED_SERVER_ERROR") {
setShowBetaError(true);
return;
}
}, [data, router]);