Skip to content

Commit

Permalink
Merge pull request #14 from Freelancer-god/feat/roles
Browse files Browse the repository at this point in the history
Feat/roles
  • Loading branch information
onggiabayluon authored Jun 11, 2024
2 parents 3b18286 + 80ca71c commit 6ac4c38
Show file tree
Hide file tree
Showing 13 changed files with 1,134 additions and 23 deletions.
1,038 changes: 1,033 additions & 5 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"prepare": "husky | chmod ug+x .husky/*"
},
"dependencies": {
"@ant-design/cssinjs": "^1.20.0",
"@ant-design/nextjs-registry": "^1.0.0",
"@hookform/resolvers": "^3.4.2",
"@next/bundle-analyzer": "^14.2.3",
"@radix-ui/primitive": "^1.0.1",
Expand All @@ -35,6 +37,7 @@
"@tanstack/react-query": "^5.40.1",
"@tanstack/react-table": "^8.17.3",
"@uidotdev/usehooks": "^2.4.1",
"antd": "^5.18.0",
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
Expand Down Expand Up @@ -78,4 +81,4 @@
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
}
2 changes: 1 addition & 1 deletion src/app/dashboard/chihois/_components/chihois-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export function ChihoisTable<TData, TValue>({ columns, initialData, total }: Dat
debugTable: process.env.NODE_ENV === "development",
});

return <DataTable columns={columns} table={table} isLoading={isFetching} filterField="email" />;
return <DataTable columns={columns} table={table} isLoading={isFetching} filterField="name" />;
}
16 changes: 10 additions & 6 deletions src/app/dashboard/chihois/_components/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { MoreHorizontal } from "lucide-react";
import { DataTableColumnHeader } from "@/components/table/data-table-column-header";
import { Chihoi, chihoiSchema } from "@/types/chihoi";
import { Checkbox } from "@/components/ui/checkbox";
import { mergeArraysById } from "@/lib/utils";
import DeleteChihoiForm from "@/app/dashboard/chihois/_components/delete-chihoi-form";
import DropDownModalWrapper from "@/components/dropdown/dropdown-modal-wrapper";
import ChihoiForm from "@/app/dashboard/chihois/_components/chihoi-form";
import { dynamicColumns } from "@/components/table/dynamic-column";
import dayjs from "dayjs";
import UploadChihoiForm from "@/app/dashboard/chihois/_components/upload-chihoi-form";

const defaultColumns: ColumnDef<Chihoi>[] = [
{
Expand Down Expand Up @@ -66,6 +67,9 @@ const defaultColumns: ColumnDef<Chihoi>[] = [
<DropDownModalWrapper label="Delete" className="text-red-500">
<DeleteChihoiForm id={chihoi.id} />
</DropDownModalWrapper>
<DropDownModalWrapper label="Upload">
<UploadChihoiForm id={chihoi.id} />
</DropDownModalWrapper>
</DropdownMenuContent>
</DropdownMenu>
);
Expand All @@ -76,11 +80,11 @@ const defaultColumns: ColumnDef<Chihoi>[] = [

// Add, or override stuff here by specify id
const updates: ColumnDef<Chihoi>[] = [
// {
// id: "founding_date",
// accessorKey: "founding_date",
// // cell:
// },
{
id: "founding_date",
accessorFn: (d) => d["founding_date"] && dayjs(d["founding_date"]).tz("Asia/Ho_Chi_Minh").format("DD/MM/YYYY"),
// cell:
},
];

export const columns = mergeArraysById(defaultColumns, updates);
29 changes: 29 additions & 0 deletions src/app/dashboard/chihois/_components/upload-chihoi-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";
import ImageUpload from "@/components/form/antd-image-upload";
import ModalCard from "@/components/form/modal-card";
import { useDeleteChihoi } from "@/services/chihoi-service";

export default function UploadChihoiForm({ id }: { id: string }) {
// const { mutate, isPending, isSuccess, isError: isCreateBookError } = useDeleteChihoi();

const handleSubmit = (e) => {
e.preventDefault();
// mutate(id);
};

return (
<ModalCard
formId="upload-chihoi-form"
metadata={{
title: "Upload ảnh",
buttonLabel: "Upload ảnh",
}}
// onClose={isSuccess}
// isLoading={isPending}
>
<form id="upload-chihoi-form" onSubmit={handleSubmit}>
<ImageUpload onUpload={() => {}} />
</form>
</ModalCard>
);
}
5 changes: 4 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Providers } from "@/components/providers/providers";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "@/../public/globals.css";
import { AntdRegistry } from "@ant-design/nextjs-registry";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -18,7 +19,9 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<Providers>{children}</Providers>
<AntdRegistry>
<Providers>{children}</Providers>
</AntdRegistry>
</body>
</html>
);
Expand Down
40 changes: 40 additions & 0 deletions src/components/form/antd-image-upload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { FC } from "react";
import { InboxOutlined } from "@ant-design/icons";
import type { UploadProps } from "antd";
import { message, Upload } from "antd";

const { Dragger } = Upload;

const props: UploadProps = {
name: "file",
multiple: true,
action: "https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload",
onChange(info) {
const { status } = info.file;
if (status !== "uploading") {
console.log(info.file, info.fileList);
}
if (status === "done") {
message.success(`${info.file.name} file uploaded successfully.`);
} else if (status === "error") {
message.error(`${info.file.name} file upload failed.`);
}
},
onDrop(e) {
console.log("Dropped files", e.dataTransfer.files);
},
};

export default function ImageUpload({ onUpload }: { onUpload: any }) {
return (
<Dragger {...props}>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">Click or drag file to this area to upload</p>
<p className="ant-upload-hint">
Support for a single or bulk upload. Strictly prohibited from uploading company data or other banned files.
</p>
</Dragger>
);
}
6 changes: 5 additions & 1 deletion src/components/form/generic-form-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export function GenericFormField({

schema = unwrapZodSchema(schema);

if (schema instanceof z.ZodDate) return <DateTimePicker label={name} name={name} id={name} {...props} />;
if (schema instanceof z.ZodDate) {
const date = props?.value ? new Date(props.value) : null;
delete props?.value;
return <DateTimePicker label={name} name={name} id={name} jsDate={date} {...props} />;
}
if (schema instanceof z.ZodString) return <Input name={name} id={name} type="text" {...props} />;
if (schema instanceof z.ZodNumber) return <Input name={name} id={name} type="number" {...props} />;
if (schema instanceof z.ZodEnum) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export const SIDEBAR_ITEMS: MenuItem[] = [
},
];

export const CREATE_EDIT_FIELDS_EXCLUDE = ["id", "updated_at", "created_at", "last_login_at", "role"];
export const CREATE_EDIT_FIELDS_EXCLUDE = ["id", "reference", "updated_at", "created_at", "last_login_at", "role"];
export const READ_FIELDS_EXCLUDE = ["password"];
4 changes: 2 additions & 2 deletions src/services/chihoi-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const fetchChihoiById = async (id: string) => {

// Create chihoi
const createChihoi = async (chihoi: Chihoi) => {
return await fetcher<Chihoi>({ url: "/clubs/store", method: "POST", data: { ...chihoi } });
return await fetcher<Chihoi>({ url: "/clubs/store", method: "POST", data: chihoi });
};

// Delete chihoi
Expand All @@ -49,7 +49,7 @@ const editChihoi = async (chihoi: Chihoi) => {
return await fetcher<Chihoi>({
url: `/clubs/update/${chihoi.id}`,
method: "PUT",
data: { ...chihoi },
data: chihoi,
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/services/employee-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const fetchEmployeeById = async (id: string) => {

// Create employee
const createEmployee = async (employee: Employee) => {
return await fetcher<Employee>({ url: "/employees/store", method: "POST", data: { ...employee } });
return await fetcher<Employee>({ url: "/employees/store", method: "POST", data: employee });
};

// Delete employee
Expand All @@ -49,7 +49,7 @@ const editEmployee = async (employee: Employee) => {
return await fetcher<Employee>({
url: `/employees/update/${employee.id}`,
method: "PUT",
data: { ...employee },
data: employee,
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/services/role-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const fetchRoleById = async (id: string) => {

// Create role
const createRole = async (role: Role) => {
return await fetcher<Role>({ url: "/roles/store", method: "POST", data: { ...role } });
return await fetcher<Role>({ url: "/roles/store", method: "POST", data: role });
};

// Delete role
Expand All @@ -49,7 +49,7 @@ const editRole = async (role: Role) => {
return await fetcher<Role>({
url: `/roles/update/${role.id}`,
method: "PUT",
data: { ...role },
data: role,
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/types/chihoi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const chihoiSchema = z.object({
phone_zalo: z.string().regex(/^\d+$/, {
message: "Phone number should only contain digits",
}),
media: z.union([z.string(), z.number()]).optional(),
media: z.union([z.string(), z.number()]).nullable().optional(),
});
// .omit({ password: true });

Expand Down

0 comments on commit 6ac4c38

Please sign in to comment.