.
This commit is contained in:
parent
bdcda617fb
commit
587f20cd14
@ -6,23 +6,26 @@ import { DataTable } from "@/components";
|
|||||||
import { DataTableToolbar } from "@/components/DataTable/DataTableToolbar";
|
import { DataTableToolbar } from "@/components/DataTable/DataTableToolbar";
|
||||||
import { useDataTable, useDataTableContext } from "@/lib/hooks";
|
import { useDataTable, useDataTableContext } from "@/lib/hooks";
|
||||||
import { IListQuotes_Response_DTO, MoneyValue, UTCDateValue } from "@shared/contexts";
|
import { IListQuotes_Response_DTO, MoneyValue, UTCDateValue } from "@shared/contexts";
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
import { ColumnDef, Row, Table } from "@tanstack/react-table";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { Trans } from "react-i18next";
|
import { Trans } from "react-i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useQuotesList } from "../hooks";
|
import { useQuotes } from "../hooks";
|
||||||
|
|
||||||
export const QuotesDataTable = () => {
|
export const QuotesDataTable = ({ status = "all" }: { status?: string }) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { pagination, globalFilter, isFiltered } = useDataTableContext();
|
const { pagination, globalFilter, isFiltered } = useDataTableContext();
|
||||||
|
|
||||||
const { data, isPending, isError, error } = useQuotesList({
|
const { useList } = useQuotes();
|
||||||
|
|
||||||
|
const { data, isPending, isError, error } = useList({
|
||||||
pagination: {
|
pagination: {
|
||||||
pageIndex: pagination.pageIndex,
|
pageIndex: pagination.pageIndex,
|
||||||
pageSize: pagination.pageSize,
|
pageSize: pagination.pageSize,
|
||||||
},
|
},
|
||||||
searchTerm: globalFilter,
|
status,
|
||||||
|
quickSearchTerm: globalFilter,
|
||||||
});
|
});
|
||||||
|
|
||||||
const columns = useMemo<ColumnDef<IListQuotes_Response_DTO, any>[]>(
|
const columns = useMemo<ColumnDef<IListQuotes_Response_DTO, any>[]>(
|
||||||
|
|||||||
@ -68,7 +68,24 @@ export const QuoteEdit = () => {
|
|||||||
precision: 2,
|
precision: 2,
|
||||||
currency_code: data?.currency_code,
|
currency_code: data?.currency_code,
|
||||||
},
|
},
|
||||||
items: [],
|
items: [
|
||||||
|
{
|
||||||
|
subtotal_price: {
|
||||||
|
amount: undefined,
|
||||||
|
precision: 4,
|
||||||
|
currency_code: data?.currency_code,
|
||||||
|
},
|
||||||
|
discount: {
|
||||||
|
amount: undefined,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
total_price: {
|
||||||
|
amount: undefined,
|
||||||
|
precision: 4,
|
||||||
|
currency_code: data?.currency_code,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,2 @@
|
|||||||
export * from "./useDetailColumns";
|
export * from "./useDetailColumns";
|
||||||
export * from "./useQuotes";
|
export * from "./useQuotes";
|
||||||
export * from "./useQuotesList";
|
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import { useOne, useSave } from "@/lib/hooks/useDataSource";
|
import { UseListQueryResult, useList, useOne, useSave } from "@/lib/hooks/useDataSource";
|
||||||
|
import {
|
||||||
|
IFilterItemDataProviderParam,
|
||||||
|
IGetListDataProviderParams,
|
||||||
|
} from "@/lib/hooks/useDataSource/DataSource";
|
||||||
import { TDataSourceError } from "@/lib/hooks/useDataSource/types";
|
import { TDataSourceError } from "@/lib/hooks/useDataSource/types";
|
||||||
import { useDataSource } from "@/lib/hooks/useDataSource/useDataSource";
|
import { useDataSource } from "@/lib/hooks/useDataSource/useDataSource";
|
||||||
import { useQueryKey } from "@/lib/hooks/useQueryKey";
|
import { useQueryKey } from "@/lib/hooks/useQueryKey";
|
||||||
@ -6,21 +10,79 @@ import {
|
|||||||
ICreateQuote_Request_DTO,
|
ICreateQuote_Request_DTO,
|
||||||
ICreateQuote_Response_DTO,
|
ICreateQuote_Response_DTO,
|
||||||
IGetQuote_Response_DTO,
|
IGetQuote_Response_DTO,
|
||||||
|
IListQuotes_Response_DTO,
|
||||||
|
IListResponse_DTO,
|
||||||
IUpdateQuote_Request_DTO,
|
IUpdateQuote_Request_DTO,
|
||||||
IUpdateQuote_Response_DTO,
|
IUpdateQuote_Response_DTO,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
} from "@shared/contexts";
|
} from "@shared/contexts";
|
||||||
|
|
||||||
|
export type UseQuotesListParams = Omit<IGetListDataProviderParams, "filters" | "resource"> & {
|
||||||
|
status?: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
queryOptions?: Record<string, unknown>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UseQuotesListResponse = UseListQueryResult<
|
||||||
|
IListResponse_DTO<IListQuotes_Response_DTO>,
|
||||||
|
unknown
|
||||||
|
>;
|
||||||
|
|
||||||
export type UseQuotesGetParamsType = {
|
export type UseQuotesGetParamsType = {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
queryOptions?: Record<string, unknown>;
|
queryOptions?: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const quoteStatusFilter: Record<string, IFilterItemDataProviderParam> = {
|
||||||
|
draft: {
|
||||||
|
field: "status",
|
||||||
|
operator: "eq",
|
||||||
|
value: "draft",
|
||||||
|
},
|
||||||
|
archived: {
|
||||||
|
field: "status",
|
||||||
|
operator: "eq",
|
||||||
|
value: "archived",
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
field: "status",
|
||||||
|
operator: "eq",
|
||||||
|
value: "active",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const useQuotes = () => {
|
export const useQuotes = () => {
|
||||||
const dataSource = useDataSource();
|
const dataSource = useDataSource();
|
||||||
const keys = useQueryKey();
|
const keys = useQueryKey();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
useList: (params: UseQuotesListParams): UseQuotesListResponse => {
|
||||||
|
const dataSource = useDataSource();
|
||||||
|
const keys = useQueryKey();
|
||||||
|
|
||||||
|
const {
|
||||||
|
pagination,
|
||||||
|
status = "draft",
|
||||||
|
quickSearchTerm = undefined,
|
||||||
|
enabled = true,
|
||||||
|
queryOptions,
|
||||||
|
} = params;
|
||||||
|
|
||||||
|
return useList({
|
||||||
|
queryKey: keys().data().resource("quotes").action("list").params(params).get(),
|
||||||
|
queryFn: () => {
|
||||||
|
return dataSource.getList({
|
||||||
|
resource: "quotes",
|
||||||
|
quickSearchTerm,
|
||||||
|
filters: status !== "all" ? Array.of(quoteStatusFilter[status]) : undefined,
|
||||||
|
pagination,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
enabled,
|
||||||
|
queryOptions,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
useOne: (id?: string, params?: UseQuotesGetParamsType) =>
|
useOne: (id?: string, params?: UseQuotesGetParamsType) =>
|
||||||
useOne<IGetQuote_Response_DTO>({
|
useOne<IGetQuote_Response_DTO>({
|
||||||
queryKey: keys().data().resource("quotes").action("one").id("").params().get(),
|
queryKey: keys().data().resource("quotes").action("one").id("").params().get(),
|
||||||
@ -36,17 +98,16 @@ export const useQuotes = () => {
|
|||||||
useSave<ICreateQuote_Response_DTO, TDataSourceError, ICreateQuote_Request_DTO>({
|
useSave<ICreateQuote_Response_DTO, TDataSourceError, ICreateQuote_Request_DTO>({
|
||||||
mutationKey: keys().data().resource("quotes").action("one").id("").params().get(),
|
mutationKey: keys().data().resource("quotes").action("one").id("").params().get(),
|
||||||
mutationFn: (data) => {
|
mutationFn: (data) => {
|
||||||
let { id, status } = data;
|
const { date } = data;
|
||||||
|
|
||||||
if (!id) {
|
const id = UniqueID.generateNewID().object.toString();
|
||||||
id = UniqueID.generateNewID().object.toString();
|
const status = "draft";
|
||||||
status = "draft";
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataSource.createOne({
|
return dataSource.createOne({
|
||||||
resource: "quotes",
|
resource: "quotes",
|
||||||
data: {
|
data: {
|
||||||
...data,
|
...data,
|
||||||
|
date: new Date(date).toISOString().slice(0, 10),
|
||||||
status,
|
status,
|
||||||
id,
|
id,
|
||||||
},
|
},
|
||||||
@ -58,14 +119,14 @@ export const useQuotes = () => {
|
|||||||
useSave<IUpdateQuote_Response_DTO, TDataSourceError, IUpdateQuote_Request_DTO>({
|
useSave<IUpdateQuote_Response_DTO, TDataSourceError, IUpdateQuote_Request_DTO>({
|
||||||
mutationKey: keys().data().resource("quotes").action("one").id(id).params().get(),
|
mutationKey: keys().data().resource("quotes").action("one").id(id).params().get(),
|
||||||
mutationFn: (data) => {
|
mutationFn: (data) => {
|
||||||
const { date: quoteDate } = data;
|
const { date } = data;
|
||||||
|
|
||||||
return dataSource.updateOne({
|
return dataSource.updateOne({
|
||||||
resource: "quotes",
|
resource: "quotes",
|
||||||
id,
|
id,
|
||||||
data: {
|
data: {
|
||||||
...data,
|
...data,
|
||||||
date: new Date(quoteDate).toISOString().slice(0, 10),
|
date: new Date(date).toISOString().slice(0, 10),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
import { UseListQueryResult, useList } from "@/lib/hooks/useDataSource";
|
|
||||||
import { useDataSource } from "@/lib/hooks/useDataSource/useDataSource";
|
|
||||||
import { useQueryKey } from "@/lib/hooks/useQueryKey";
|
|
||||||
import { IListQuotes_Response_DTO, IListResponse_DTO } from "@shared/contexts";
|
|
||||||
|
|
||||||
export type UseQuotesListParams = {
|
|
||||||
pagination: {
|
|
||||||
pageIndex: number;
|
|
||||||
pageSize: number;
|
|
||||||
};
|
|
||||||
searchTerm?: string;
|
|
||||||
enabled?: boolean;
|
|
||||||
queryOptions?: Record<string, unknown>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type UseQuotesListResponse = UseListQueryResult<
|
|
||||||
IListResponse_DTO<IListQuotes_Response_DTO>,
|
|
||||||
unknown
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const useQuotesList = (params: UseQuotesListParams): UseQuotesListResponse => {
|
|
||||||
const dataSource = useDataSource();
|
|
||||||
const keys = useQueryKey();
|
|
||||||
|
|
||||||
const { pagination, searchTerm = undefined, enabled = true, queryOptions } = params;
|
|
||||||
|
|
||||||
return useList({
|
|
||||||
queryKey: keys().data().resource("quotes").action("list").params(params).get(),
|
|
||||||
queryFn: () => {
|
|
||||||
return dataSource.getList({
|
|
||||||
resource: "quotes",
|
|
||||||
quickSearchTerm: searchTerm,
|
|
||||||
pagination,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
enabled,
|
|
||||||
queryOptions,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -2,7 +2,7 @@ import { DataTableProvider } from "@/lib/hooks";
|
|||||||
import { Trans } from "react-i18next";
|
import { Trans } from "react-i18next";
|
||||||
import { QuotesDataTable } from "./components";
|
import { QuotesDataTable } from "./components";
|
||||||
|
|
||||||
import { Button } from "@/ui";
|
import { Button, Tabs, TabsContent, TabsList, TabsTrigger } from "@/ui";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
@ -16,14 +16,44 @@ export const QuotesList = () => {
|
|||||||
<h2 className='text-2xl font-bold tracking-tight'>
|
<h2 className='text-2xl font-bold tracking-tight'>
|
||||||
<Trans i18nKey='quotes.list.title' />
|
<Trans i18nKey='quotes.list.title' />
|
||||||
</h2>
|
</h2>
|
||||||
<p className='text-muted-foreground'>descripción</p>
|
<p className='text-muted-foreground'>
|
||||||
|
<Trans i18nKey='quotes.list.subtitle' />
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center space-x-2'>
|
<div className='flex items-center space-x-2'>
|
||||||
<Button onClick={() => navigate("/quotes/add")}>{t("quotes.create.title")}</Button>
|
<Button onClick={() => navigate("/quotes/add")}>{t("quotes.create.title")}</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<QuotesDataTable />
|
<Tabs defaultValue='all'>
|
||||||
|
<div className='flex items-center'>
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value='all'>
|
||||||
|
<Trans i18nKey='quotes.list.tabs.all' />
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value='active'>Active</TabsTrigger>
|
||||||
|
<TabsTrigger value='draft'>
|
||||||
|
<Trans i18nKey='quotes.list.tabs.draft' />
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value='archived' className='hidden sm:flex'>
|
||||||
|
<Trans i18nKey='quotes.list.tabs.archived' />
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<div className='flex items-center gap-2 ml-auto'></div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value='all'>
|
||||||
|
<QuotesDataTable status='all' />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value='draft'>
|
||||||
|
<QuotesDataTable status='draft' />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value='archived'>
|
||||||
|
<QuotesDataTable status='archived' />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value='active'>
|
||||||
|
<QuotesDataTable status='active' />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
</DataTableProvider>
|
</DataTableProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,9 +21,9 @@ const onRequestError = (error: AxiosError): Promise<AxiosError> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onResponse = (response: AxiosResponse): AxiosResponse => {
|
const onResponse = (response: AxiosResponse): AxiosResponse => {
|
||||||
console.group("[response]");
|
/*console.group("[response]");
|
||||||
console.dir(response);
|
console.dir(response);
|
||||||
console.groupEnd();
|
console.groupEnd();*/
|
||||||
|
|
||||||
const config = response?.config;
|
const config = response?.config;
|
||||||
if (config.raw) {
|
if (config.raw) {
|
||||||
|
|||||||
@ -78,6 +78,12 @@
|
|||||||
"quotes": {
|
"quotes": {
|
||||||
"list": {
|
"list": {
|
||||||
"title": "Cotizaciones",
|
"title": "Cotizaciones",
|
||||||
|
"subtitle": "",
|
||||||
|
"tabs": {
|
||||||
|
"all": "Todas",
|
||||||
|
"draft": "Borrador",
|
||||||
|
"archived": "Archivadas"
|
||||||
|
},
|
||||||
"columns": {
|
"columns": {
|
||||||
"date": "Fecha",
|
"date": "Fecha",
|
||||||
"reference": "Referencia",
|
"reference": "Referencia",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user