feat: add api generation

This commit is contained in:
BennyKok
2023-12-15 17:58:19 +08:00
parent e77da089d9
commit bbb7f398ab
15 changed files with 1213 additions and 45 deletions
+1 -15
View File
@@ -2,6 +2,7 @@
import { getRelativeTime } from "../lib/getRelativeTime";
import { LoadingIcon } from "./LoadingIcon";
import { callServerPromise } from "./callServerPromise";
import {
FormControl,
FormField,
@@ -56,7 +57,6 @@ import {
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
import * as React from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";
export type Machine = {
@@ -176,20 +176,6 @@ export const columns: ColumnDef<Machine>[] = [
},
];
export async function callServerPromise<T>(result: Promise<T>) {
return result
.then((x) => {
if ((x as { message: string })?.message !== undefined) {
toast.success((x as { message: string }).message);
}
return x;
})
.catch((error) => {
toast.error(error.message);
return null;
});
}
export function MachineList({ data }: { data: Machine[] }) {
const [sorting, setSorting] = React.useState<SortingState>([]);
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(