diff --git a/package.json b/package.json index 773c874..4134798 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "dev": "vite", "build": "vite build", - "preview": "vite preview" + "preview": "vite preview", + "lint": "npx tsc --noEmit" }, "dependencies": { "@chakra-ui/react": "^2.8.2", @@ -65,4 +66,4 @@ "last 1 safari version" ] } -} +} \ No newline at end of file diff --git a/src/component/customTable/SearchFiltersClearBtn.tsx b/src/component/customTable/SearchFiltersClearBtn.tsx index 0ccf91e..bf6ae26 100644 --- a/src/component/customTable/SearchFiltersClearBtn.tsx +++ b/src/component/customTable/SearchFiltersClearBtn.tsx @@ -5,7 +5,9 @@ interface SearchFiltersClearBtnProps { isLoading?: boolean } -export const SearchFiltersClearBtn = ( +export const SearchFiltersClearBtn = < + SearchFilterType extends Record, +>( props: SearchFiltersClearBtnProps, ) => { const { isLoading } = props diff --git a/src/component/customTable/SearchPopoverContent.tsx b/src/component/customTable/SearchPopoverContent.tsx index e6b9560..2ed4f0f 100644 --- a/src/component/customTable/SearchPopoverContent.tsx +++ b/src/component/customTable/SearchPopoverContent.tsx @@ -9,13 +9,17 @@ import { import { useTableContext } from "context/table" import { ChangeEvent, MutableRefObject, useEffect, useState } from "react" -interface SearchPopoverContentProps { +interface SearchPopoverContentProps< + SearchFilterType extends Record, +> { initialRef: MutableRefObject param: keyof SearchFilterType onClose: () => void } -export const SearchPopoverContent = ( +export const SearchPopoverContent = < + SearchFilterType extends Record, +>( props: SearchPopoverContentProps, ) => { const { initialRef, param, onClose } = props @@ -35,7 +39,7 @@ export const SearchPopoverContent = ( } const handleSearchFilterChange = () => { - setSortField(param as string) + setSortField(param) setSearchFilter( (prevSearchFilter) => diff --git a/src/component/orderProcessing/EngravingChatAndButtons.tsx b/src/component/orderProcessing/EngravingChatAndButtons.tsx index e415b4f..ebfa8cb 100644 --- a/src/component/orderProcessing/EngravingChatAndButtons.tsx +++ b/src/component/orderProcessing/EngravingChatAndButtons.tsx @@ -8,21 +8,24 @@ import { FC } from "react" interface EngravingChatAndButtonsProps { isOrderHasTicket?: boolean isViewOnlyMode?: boolean + isForTickets?: boolean } export const EngravingChatAndButtons: FC = ( props, ) => { - const { isOrderHasTicket, isViewOnlyMode } = props + const { isOrderHasTicket, isViewOnlyMode, isForTickets } = props const { canReadTicketMessages } = useUserPermissions() return ( - + {!isForTickets && ( + + )} {isOrderHasTicket && canReadTicketMessages && } diff --git a/src/component/orderProcessing/EngravingPanel.tsx b/src/component/orderProcessing/EngravingPanel.tsx index 2769020..62b13be 100644 --- a/src/component/orderProcessing/EngravingPanel.tsx +++ b/src/component/orderProcessing/EngravingPanel.tsx @@ -9,10 +9,12 @@ interface EngravingPanelProps { processingOrder: WithId isOrderHasTicket?: boolean isViewOnlyMode?: boolean + isForTickets?: boolean } export const EngravingPanel: FC = (props) => { - const { processingOrder, isOrderHasTicket, isViewOnlyMode } = props + const { processingOrder, isOrderHasTicket, isViewOnlyMode, isForTickets } = + props return ( @@ -21,6 +23,7 @@ export const EngravingPanel: FC = (props) => { ) diff --git a/src/context/table.tsx b/src/context/table.tsx index 767bd18..9b6494e 100644 --- a/src/context/table.tsx +++ b/src/context/table.tsx @@ -8,14 +8,14 @@ import { } from "react" import { SortDirection } from "type/sortDirection" -interface TableContextProps { +interface TableContextProps> { sortDirection?: SortDirection isAscSort?: boolean isDescSort?: boolean isNoSort?: boolean setSortDirection: Dispatch> - sortField?: string - setSortField: Dispatch> + sortField?: keyof SearchFilterType + setSortField: Dispatch> searchFilter?: SearchFilterType setSearchFilter: Dispatch> @@ -27,7 +27,9 @@ export const TableContext = createContext | undefined>( ) //* - is a providable type -export const TableContextProvider = ( +export const TableContextProvider = < + SearchFilterType extends Record, +>( props: PropsWithChildren<{}>, ) => { const { children } = props @@ -35,7 +37,9 @@ export const TableContextProvider = ( const [sortDirection, setSortDirection] = useState< SortDirection | undefined >() - const [sortField, setSortField] = useState() + const [sortField, setSortField] = useState< + keyof SearchFilterType | undefined + >() const [searchFilter, setSearchFilter] = useState() @@ -43,13 +47,13 @@ export const TableContextProvider = ( const isDescSort = sortDirection === "desc" const isNoSort = sortDirection === undefined - const getSearchFilterValue = (param: any) => { + const getSearchFilterValue = (param: K) => { if ( searchFilter && Object.prototype.hasOwnProperty.call(searchFilter, param) ) { - const value = searchFilter[param as keyof SearchFilterType] - if (value) { + const value = searchFilter[param] + if (value !== undefined && value !== null) { return String(value) } } @@ -57,29 +61,29 @@ export const TableContextProvider = ( return "" } - return ( - + searchFilter, + setSearchFilter, + getSearchFilterValue, + } as TableContextProps + + return ( + }> {children} ) } export const useTableContext = < - SearchFilterType, + SearchFilterType extends Record = Record, >(): TableContextProps => { const context = useContext(TableContext) diff --git a/src/page/Tickets.tsx b/src/page/Tickets.tsx index 0d4041d..1afc57c 100644 --- a/src/page/Tickets.tsx +++ b/src/page/Tickets.tsx @@ -24,7 +24,12 @@ export const Tickets = (props: PageProps) => { const { data: ticketsResponse, isLoading } = useQuery< ApiResponse[]> - >("ticketsList", () => getAllTickets({})) + >("ticketsList", () => + getAllTickets({ + sortField: "id", + sortDirection: "desc", + }), + ) const ticketsList = ticketsResponse?.result return ( @@ -54,6 +59,7 @@ export const Tickets = (props: PageProps) => { processingOrder={openedTicketProcessingOrder!} isOrderHasTicket={isOpenedTicketExists} isViewOnlyMode + isForTickets /> )} diff --git a/src/type/api/apiRequest.ts b/src/type/api/apiRequest.ts index e4e4da1..da87d4d 100644 --- a/src/type/api/apiRequest.ts +++ b/src/type/api/apiRequest.ts @@ -1,4 +1,5 @@ import { SortDirection } from "type/sortDirection" +import { WithId } from "type/withId" export type LimitOffset = { limit?: number @@ -7,7 +8,7 @@ export type LimitOffset = { export type ApiRequest = LimitOffset & { shopId?: number - sortField?: string + sortField?: keyof WithId sortDirection?: SortDirection searchFilter?: SearchFilterType }