-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: client service table display
- Loading branch information
1 parent
454b9ca
commit bbd299c
Showing
28 changed files
with
340 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import apis from "./axios"; | ||
import { SERVICE_ALL, SERVICE_W_CLIENT } from "./req_list"; | ||
import { RES_STATUS } from "@/configs/types"; | ||
|
||
export const serviceAll = async () => { | ||
try { | ||
const response = await apis.get(SERVICE_ALL); | ||
return response.data; | ||
} catch (err: unknown) { | ||
console.log("-> retrieve all service error: ", err); | ||
return { | ||
status: RES_STATUS.FAILED, | ||
msg: "failed in retrieving all services", | ||
data: "", | ||
}; | ||
} | ||
}; | ||
|
||
export const serviceWClient = async (cid: string) => { | ||
try { | ||
const response = await apis.post(SERVICE_W_CLIENT, { cid }); | ||
return response.data; | ||
} catch (err: unknown) { | ||
console.log("-> retrieve client services error: ", err); | ||
return { | ||
status: RES_STATUS.FAILED, | ||
msg: "failed in retrieving client services", | ||
data: "", | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { FC, ReactNode } from "react"; | ||
import { useSubmit } from "react-router-dom"; | ||
import { useRouterStore } from "@/configs/zustore"; | ||
import { capFirstLetter, genAction } from "@/lib/literals"; | ||
import { ORDER_STATUS } from "@/configs/utils/setting"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
// DropdownMenuLabel, | ||
// DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { statusColor } from "@/configs/utils/color"; | ||
import { TclientService } from "@/configs/schema/serviceSchema"; | ||
|
||
type Tprops = { | ||
mLabel: ReactNode | string; | ||
data: TclientService; | ||
}; | ||
|
||
// this menu btn group component is highly designed for order status change usage | ||
const ServiceStatusBtn: FC<Tprops> = ({ mLabel, data }) => { | ||
const submit = useSubmit(); | ||
const currentRouter = useRouterStore((state) => state.currentRouter); | ||
|
||
const handleClick = async (csid: string, status: string) => { | ||
submit( | ||
{ req: "ServiceStatus", csid, status }, | ||
{ | ||
method: "PUT", | ||
action: | ||
currentRouter === "client" | ||
? genAction(currentRouter, data.fk_cid) | ||
: genAction(currentRouter), | ||
} | ||
); | ||
}; | ||
|
||
const menuContent = ORDER_STATUS.map((item, index) => { | ||
if (item.toLocaleLowerCase() === data.status.toLocaleLowerCase()) | ||
return; | ||
|
||
return ( | ||
<DropdownMenuItem | ||
key={index} | ||
className={`${statusColor[item].text} ${statusColor[item].fbg} ${statusColor[item].ftext}`} | ||
> | ||
<div | ||
onClick={() => { | ||
//e.preventDefault(); | ||
handleClick(data.csid, item); | ||
}} | ||
className="flex w-full items-center rounded-md px-2 text-md font-bold" | ||
> | ||
{capFirstLetter(item)} | ||
</div> | ||
</DropdownMenuItem> | ||
); | ||
}).filter((item) => item !== null && item !== undefined); | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="outline-none ring-0 cursor-pointer"> | ||
{mLabel} | ||
</DropdownMenuTrigger> | ||
{menuContent ? ( | ||
<DropdownMenuContent>{menuContent}</DropdownMenuContent> | ||
) : null} | ||
</DropdownMenu> | ||
); | ||
}; | ||
|
||
export default ServiceStatusBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { ColumnDef, CellContext } from "@tanstack/react-table"; | ||
import i18n from "@/configs/i18n"; | ||
import { TclientService } from "../schema/serviceSchema"; | ||
import ServiceStatusBtn from "@/components/table/tableBtn/ServiceStatusBtn"; | ||
import { StatusBadge } from "@/components/Badge"; | ||
import { TstatusColor } from "../types"; | ||
import { dateFormat } from "@/lib/time"; | ||
|
||
const useClientServiceColumnsDef = () => { | ||
const clientServiceColumns: ColumnDef<TclientService>[] = [ | ||
/* { | ||
id: "Menu", | ||
header: i18n.t("label.menu"), | ||
}, */ | ||
|
||
{ | ||
id: "csid", | ||
header: i18n.t("label.serviceID"), | ||
accessorKey: "csid", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap">{info.getValue<string>()}</span> | ||
), | ||
}, | ||
{ | ||
id: "title", | ||
header: i18n.t("label.title"), | ||
accessorKey: "title", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap">{info.getValue<string>()}</span> | ||
), | ||
}, | ||
{ | ||
id: "type", | ||
header: i18n.t("label.serviceType"), | ||
accessorKey: "service_type", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap">{info.getValue<string>()}</span> | ||
), | ||
}, | ||
{ | ||
id: "productName", | ||
header: i18n.t("label.productName"), | ||
accessorKey: "product_name", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap">{info.getValue<string>()}</span> | ||
), | ||
}, | ||
{ | ||
id: "serviceStatus", | ||
header: i18n.t("label.status"), | ||
accessorKey: "status", | ||
cell: (info: CellContext<TclientService, unknown>) => { | ||
return ( | ||
<ServiceStatusBtn | ||
mLabel={ | ||
<StatusBadge | ||
value={info.getValue() as TstatusColor} | ||
/> | ||
} | ||
data={info.row.original as TclientService} | ||
/> | ||
); | ||
}, | ||
meta: { | ||
filterVariant: "select", | ||
}, | ||
}, | ||
{ | ||
id: "createdDate", | ||
header: i18n.t("label.createdDate"), | ||
accessorKey: "created_date", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap"> | ||
{dateFormat(info.getValue<string>(), "au")} | ||
</span> | ||
), | ||
}, | ||
{ | ||
id: "expiryDate", | ||
header: i18n.t("label.expiredDate"), | ||
accessorKey: "expiry_date", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap">{info.getValue<string>()}</span> | ||
), | ||
}, | ||
{ | ||
id: "note", | ||
header: i18n.t("label.note"), | ||
accessorKey: "note", | ||
cell: (info: CellContext<TclientService, unknown>) => ( | ||
<span className="text-wrap">{info.getValue<string>()}</span> | ||
), | ||
}, | ||
]; | ||
return clientServiceColumns; | ||
}; | ||
|
||
export default useClientServiceColumnsDef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { z } from "zod"; | ||
import { ORDER_STATUS } from "../utils/setting"; | ||
|
||
export const serviceSchema = z.object({ | ||
csid: z.string().default(""), | ||
fk_cid: z.string().default(""), | ||
title: z.string().trim().default(""), | ||
service_type: z.string().trim().default(""), | ||
product_name: z.string().trim().default(""), | ||
status: z.string().default(ORDER_STATUS[0]), // pending | ||
created_date: z.string().datetime().nullable().default(null), | ||
expiry_date: z.string().datetime().nullable().default(null), | ||
archive: z.boolean().default(false), | ||
note: z.string().trim().default(""), | ||
}); | ||
|
||
export type TclientService = z.infer<typeof serviceSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.