From 7cc30dc1425bba6e71292018781fe83634c9f2d8 Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 12 May 2025 15:16:00 +0700 Subject: [PATCH] update view admin --- .../src/components/bid/delete-row-action.tsx | 22 + .../src/components/dashboard/working-page.tsx | 45 +- auto-bid-admin/src/lib/table/action.tsx | 436 ++++++++++-------- .../src/lib/zustand/use-chooses-store.ts | 18 + auto-bid-admin/src/pages/bids.tsx | 193 ++++---- auto-bid-tool/index.js | 6 - 6 files changed, 427 insertions(+), 293 deletions(-) create mode 100644 auto-bid-admin/src/components/bid/delete-row-action.tsx create mode 100644 auto-bid-admin/src/lib/zustand/use-chooses-store.ts diff --git a/auto-bid-admin/src/components/bid/delete-row-action.tsx b/auto-bid-admin/src/components/bid/delete-row-action.tsx new file mode 100644 index 0000000..29c4b04 --- /dev/null +++ b/auto-bid-admin/src/components/bid/delete-row-action.tsx @@ -0,0 +1,22 @@ +import { ActionIcon } from "@mantine/core"; +import { IconTrash } from "@tabler/icons-react"; +import { useChoosesStore } from "../../lib/zustand/use-chooses-store"; +import { IBid } from "../../system/type"; + +export interface IDeleteRowActionProps { + onClick?: () => void; + data: IBid +} + +export default function DeleteRowAction({ data,onClick }: IDeleteRowActionProps) { + + + const {chooses} = useChoosesStore() + + + return ( + item.id === data.id)} onClick={onClick} size={"sm"} color="red"> + + + ); +} diff --git a/auto-bid-admin/src/components/dashboard/working-page.tsx b/auto-bid-admin/src/components/dashboard/working-page.tsx index 89359c9..1de66a4 100644 --- a/auto-bid-admin/src/components/dashboard/working-page.tsx +++ b/auto-bid-admin/src/components/dashboard/working-page.tsx @@ -6,8 +6,16 @@ import { Socket } from "socket.io-client"; import { getImagesWorking } from "../../apis/bid"; import { useStatusToolStore } from "../../lib/zustand/use-status-tool-store"; import { IBid, IWebBid } from "../../system/type"; -import { cn, extractDomainSmart, findNearestClosingChild, isTimeReached, stringToColor, subtractSeconds } from "../../utils"; +import { + cn, + extractDomainSmart, + findNearestClosingChild, + isTimeReached, + stringToColor, + subtractSeconds, +} from "../../utils"; import ShowImageModal from "./show-image-modal"; +import { IconExternalLink, IconImageInPicture } from "@tabler/icons-react"; export interface IWorkingPageProps { data: (IBid | IWebBid) & { type: string }; socket: Socket; @@ -110,9 +118,8 @@ export default function WorkingPage({ data, socket }: IWorkingPageProps) { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - - if(!isIBid(data)){ - console.log(data) + if (!isIBid(data)) { + console.log(data); } return ( @@ -144,20 +151,24 @@ export default function WorkingPage({ data, socket }: IWorkingPageProps) { {`Current price: $${data.current_price}`} )} - - {moment(lastUpdate).format("HH:mm:ss DD/MM/YYYY")} - - {!isIBid(data) && {`TT: ${moment(subtractSeconds(findNearestClosingChild(data)?.close_time || '', data.early_tracking_seconds)).format( - "HH:mm:ss DD/MM/YYYY" - )}`}} + {!isIBid(data) && ( + + {`TT: ${moment( + subtractSeconds( + findNearestClosingChild(data)?.close_time || "", + data.early_tracking_seconds + ) + ).format("HH:mm:ss DD/MM/YYYY")}`} + + )} {isIBid(data) && ( - + + + + + ); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [action, opened, close, renderComfirm]); - const actionDataMemo = useMemo(() => { - const newActions = actions?.reduce((prev, cur) => { - prev.push({ value: String(cur.key), label: cur.title, disabled: cur?.disabled ? cur.disabled(chooses || []) : false }); - return prev; - }, [] as { value: string; label: string; disabled: boolean }[]); + useEffect(() => { + if (!initFilter) return; - return newActions; - }, [actions, chooses]); + const params = initFilter.reduce((prev, cur) => { + if (cur.key === searchKey) { + prev[cur.key] = cur.type; + } + return prev; + }, {} as Record); - const handleClose = () => { - close(); - setAction(null); - setSelectValue(null); + form.setValues(params); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [initFilter]); - if (onCloseComfirm) { - onCloseComfirm(); - } - }; + useEffect(() => { + setIsLoading(!!loading); + }, [loading]); - const handleClearAction = () => { - setAction(null); - setSelectValue(null); - }; + useImperativeHandle( + refAction, + () => { + return { + setAction, + clearAction: handleClearAction, + }; + }, + [] + ); - const comfirmViewMemo = useMemo(() => { - if (!action || !action.comfirmAction) return; - - return renderComfirm ? ( - renderComfirm(action) - ) : ( - - - {action?.comfirmOption && action?.comfirmOption(action)?.title ? action.comfirmOption(action).title : 'Are you sure to execute this action'} - -
- - -
-
- ); - }, [action, opened, close, renderComfirm]); - - useEffect(() => { - if (!initFilter) return; - - const params = initFilter.reduce((prev, cur) => { - if (cur.key === searchKey) { - prev[cur.key] = cur.type; - } - return prev; - }, {} as Record); - - form.setValues(params); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [initFilter]); - - useEffect(() => { - setIsLoading(!!loading); - }, [loading]); - - useImperativeHandle( - refAction, - () => { - return { - setAction, - clearAction: handleClearAction, - }; - }, - [], - ); - - return ( - - {showSearch && searchOptions?.render ? ( - searchOptions.render() - ) : ( -
- } - rightSection={ - form.getValues()[searchKey].length ? : undefined - } - placeholder="Search by keyword" - size="xs" - label={'Search'} - {...searchOptions?.props} - /> - - )} - {showAction && ( -
- ); + )} + + {comfirmViewMemo} +
+ ); } diff --git a/auto-bid-admin/src/lib/zustand/use-chooses-store.ts b/auto-bid-admin/src/lib/zustand/use-chooses-store.ts new file mode 100644 index 0000000..df6c7a9 --- /dev/null +++ b/auto-bid-admin/src/lib/zustand/use-chooses-store.ts @@ -0,0 +1,18 @@ +// stores/useChooseStore.ts +import { create } from "zustand"; +import { IBid } from "../../system/type"; + +interface ChoosesStore { + chooses: IBid[]; + setChooses: (items: IBid[]) => void; + addChoose: (item: IBid) => void; +} + +export const useChoosesStore = create((set) => ({ + chooses: [], + setChooses: (items) => set({ chooses: items }), + addChoose: (item) => + set((state) => ({ + chooses: [...state.chooses, item], + })), +})); diff --git a/auto-bid-admin/src/pages/bids.tsx b/auto-bid-admin/src/pages/bids.tsx index 36b5584..9fd816c 100644 --- a/auto-bid-admin/src/pages/bids.tsx +++ b/auto-bid-admin/src/pages/bids.tsx @@ -1,4 +1,13 @@ -import { ActionIcon, Anchor, Badge, Box, Menu, Text, Tooltip } from "@mantine/core"; +import { + ActionIcon, + Anchor, + Badge, + Box, + Button, + Menu, + Text, + Tooltip, +} from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { IconAd, @@ -7,7 +16,7 @@ import { IconHammer, IconHistory, IconMenu, - IconTrash + IconPlus } from "@tabler/icons-react"; import _ from "lodash"; import { useMemo, useRef, useState } from "react"; @@ -18,9 +27,11 @@ import { ShowHistoriesBidPicklesApiModal, ShowHistoriesModal, } from "../components/bid"; +import DeleteRowAction from "../components/bid/delete-row-action"; import constants, { haveHistories } from "../constant"; import Table from "../lib/table/table"; import { IColumn, TRefTableFn } from "../lib/table/type"; +import { useChoosesStore } from "../lib/zustand/use-chooses-store"; import { useConfirmStore } from "../lib/zustand/use-confirm"; import { mappingStatusColors } from "../system/constants"; import { IBid } from "../system/type"; @@ -31,6 +42,8 @@ export default function Bids() { const [clickData, setClickData] = useState(null); + const {setChooses} = useChoosesStore() + const { setConfirm } = useConfirmStore(); const [openedHistories, historiesModel] = useDisclosure(false); @@ -52,9 +65,16 @@ export default function Bids() { title: "Name", typeFilter: "text", renderRow(row) { - - - return {row.name} + return ( + + {row.name} + + ); }, }, { @@ -157,7 +177,7 @@ export default function Bids() { const handleDelete = (bid: IBid) => { setConfirm({ title: "Delete ?", - message: "This bid will be delete", + message: `This bid will be delete: ${bid.name || bid.model}`, handleOk: async () => { await deleteBid(bid); @@ -192,7 +212,7 @@ export default function Bids() { const table = useMemo(() => { return ( { - bidModal.open(); - }, - }, + // { + // key: "add", + // title: "Add", + // callback: () => { + // bidModal.open(); + // }, + // }, { key: "delete", title: "Delete", @@ -228,6 +248,9 @@ export default function Bids() { disabled: (data) => data.length <= 0, }, ], + leftActionSession: ( + + ) }} refTableFn={refTableFn} striped @@ -257,84 +280,88 @@ export default function Bids() { title: Action, body: (row) => { return ( - - - e.stopPropagation()} - className="flex w-full items-center justify-center" - > - - - - - + + + + e.stopPropagation()} + className="flex w-full items-center justify-center" + > + + + + + - e.stopPropagation()}> - { - setClickData(row); - bidModal.open(); - }} - leftSection={} - > - Edit - - - { - setClickData(row); - historiesModel.open(); - }} - leftSection={} - > - Histories - - {haveHistories.includes(row?.web_bid.origin_url) && ( + e.stopPropagation()}> { setClickData(row); - switch (row.web_bid.origin_url) { - case constants.grays: { - historiesGraysApiModel.open(); - break; - } - case constants.pickles: { - historiesPicklesApiModel.open(); - break; - } - default: { - historiesGraysApiModel.open(); - } - } + bidModal.open(); }} - leftSection={} + leftSection={} > - Bids + Edit - )} - handleToggleBid(row)} - leftSection={ - row.status === "biding" ? ( - - ) : ( - - ) - } - > - {row.status === "biding" ? "Disable" : "Enable"} - + { + setClickData(row); + historiesModel.open(); + }} + leftSection={} + > + Histories + + {haveHistories.includes(row?.web_bid.origin_url) && ( + { + setClickData(row); + switch (row.web_bid.origin_url) { + case constants.grays: { + historiesGraysApiModel.open(); + break; + } + case constants.pickles: { + historiesPicklesApiModel.open(); + break; + } + default: { + historiesGraysApiModel.open(); + } + } + }} + leftSection={} + > + Bids + + )} - handleDelete(row)} - leftSection={} - > - Delete - - - + handleToggleBid(row)} + leftSection={ + row.status === "biding" ? ( + + ) : ( + + ) + } + > + {row.status === "biding" ? "Disable" : "Enable"} + + + {/* handleDelete(row)} + leftSection={} + > + Delete + */} + + + + handleDelete(row)} /> + ); }, }} diff --git a/auto-bid-tool/index.js b/auto-bid-tool/index.js index fe762b7..7065a9f 100644 --- a/auto-bid-tool/index.js +++ b/auto-bid-tool/index.js @@ -419,12 +419,6 @@ const trackingLoginStatus = async () => { login_status, }); - console.log( - "%cindex.js:422 ehehehehehe", - "color: #007acc;", - "ehehehehehe" - ); - // Set time to update login sau 1 phĂșt const now = new Date(); const oneMinuteLater = new Date(now.getTime() + 60 * 1000); -- 2.39.2