.
This commit is contained in:
parent
95edcbcdb7
commit
608169c2b9
@ -1,31 +1,7 @@
|
||||
import {
|
||||
Button,
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
Separator,
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@/ui";
|
||||
import { Button, Separator, Tooltip, TooltipContent, TooltipTrigger } from "@/ui";
|
||||
import { Table } from "@tanstack/react-table";
|
||||
import { t } from "i18next";
|
||||
import {
|
||||
CalendarIcon,
|
||||
CirclePlusIcon,
|
||||
ClockIcon,
|
||||
CopyPlusIcon,
|
||||
ForwardIcon,
|
||||
MoreVerticalIcon,
|
||||
ReplyAllIcon,
|
||||
ReplyIcon,
|
||||
ScanIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import { CirclePlusIcon, CopyPlusIcon, PackagePlusIcon, ScanIcon, Trash2Icon } from "lucide-react";
|
||||
|
||||
export const QuoteItemsSortableDataTableToolbar = ({ table }: { table: Table<unknown> }) => {
|
||||
const selectedRowsCount = table.getSelectedRowModel().rows.length;
|
||||
@ -89,112 +65,24 @@ export const QuoteItemsSortableDataTableToolbar = ({ table }: { table: Table<unk
|
||||
<div className='flex items-center gap-2'>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type='button'
|
||||
variant='ghost'
|
||||
size='icon'
|
||||
onClick={() => table.options.meta?.appendItem()}
|
||||
>
|
||||
<CirclePlusIcon className='w-4 h-4' />
|
||||
<span className='sr-only'>Añadir</span>
|
||||
<Button type='button' variant='ghost' onClick={() => table.options.meta?.appendItem()}>
|
||||
<CirclePlusIcon className='w-4 h-4 mr-2' />
|
||||
<span>{t("common.append_empty_row")}</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Añadir fila</TooltipContent>
|
||||
<TooltipContent>{t("common.append_empty_row_tooltip")}</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation='vertical' className='h-6 mx-1 bg-muted-foreground/30' />
|
||||
<Tooltip>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<TooltipTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<ClockIcon className='w-4 h-4' />
|
||||
<span className='sr-only'>Snooze</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className='flex w-[535px] p-0'>
|
||||
<div className='flex flex-col gap-2 px-2 py-4 border-r'>
|
||||
<div className='px-4 text-sm font-medium'>Snooze until</div>
|
||||
<div className='grid min-w-[250px] gap-1'>
|
||||
<Button variant='ghost' className='justify-start font-normal'>
|
||||
Later today <span className='ml-auto text-muted-foreground'></span>
|
||||
</Button>
|
||||
<Button variant='ghost' className='justify-start font-normal'>
|
||||
Tomorrow
|
||||
<span className='ml-auto text-muted-foreground'></span>
|
||||
</Button>
|
||||
<Button variant='ghost' className='justify-start font-normal'>
|
||||
This weekend
|
||||
<span className='ml-auto text-muted-foreground'></span>
|
||||
</Button>
|
||||
<Button variant='ghost' className='justify-start font-normal'>
|
||||
Next week
|
||||
<span className='ml-auto text-muted-foreground'></span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className='p-2'>
|
||||
<CalendarIcon />
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<TooltipContent>Snooze</TooltipContent>
|
||||
<TooltipTrigger asChild>
|
||||
<Button type='button' variant='ghost' onClick={() => table.options.meta?.appendItem()}>
|
||||
<PackagePlusIcon className='w-4 h-4 mr-2' />
|
||||
<span>{t("common.append_article")}</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{t("common.append_article_tooltip")}</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div className='flex items-center gap-2 ml-auto'>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<ReplyIcon className='w-4 h-4' />
|
||||
<span className='sr-only'>Reply</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Reply</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<ReplyAllIcon className='w-4 h-4' />
|
||||
<span className='sr-only'>Reply all</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Reply all</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<ForwardIcon className='w-4 h-4' />
|
||||
<span className='sr-only'>Forward</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Forward</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Separator orientation='vertical' className='h-6 mx-1 bg-muted-foreground/30' />
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<MoreVerticalIcon className='w-4 h-4' />
|
||||
<span className='sr-only'>Columnas</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align='end'>
|
||||
{table.getAllColumns().map((column) => {
|
||||
return (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={column.id}
|
||||
disabled={!column.getCanHide()}
|
||||
className='capitalize'
|
||||
checked={column.getIsVisible()}
|
||||
onCheckedChange={(value) => column.toggleVisibility(!!value)}
|
||||
>
|
||||
{column.id}
|
||||
</DropdownMenuCheckboxItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<div className='flex items-center gap-2 ml-auto'></div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -164,15 +164,15 @@ export const QuoteDetailsCardEditor = ({
|
||||
const { table, row } = props;
|
||||
return [
|
||||
{
|
||||
label: "Duplicar",
|
||||
label: t("common.duplicate_rows"),
|
||||
onClick: () => table.options.meta?.duplicateItems(row.index),
|
||||
},
|
||||
{
|
||||
label: "Insertar fila encima",
|
||||
label: t("common.insert_row_above"),
|
||||
onClick: () => table.options.meta?.insertItem(row.index),
|
||||
},
|
||||
{
|
||||
label: "Insertar fila debajo",
|
||||
label: t("common.insert_row_below"),
|
||||
onClick: () => table.options.meta?.insertItem(row.index + 1),
|
||||
},
|
||||
|
||||
@ -180,7 +180,7 @@ export const QuoteDetailsCardEditor = ({
|
||||
label: "-",
|
||||
},
|
||||
{
|
||||
label: "Eliminar",
|
||||
label: t("common.remove_row"),
|
||||
shortcut: "⌘⌫",
|
||||
onClick: () => {
|
||||
table.options.meta?.deleteItems(row.index);
|
||||
|
||||
@ -19,10 +19,6 @@ import { QuotePricesResume } from "./components";
|
||||
import { QuoteDetailsCardEditor, QuoteGeneralCardEditor } from "./components/editors";
|
||||
import { useQuotes } from "./hooks";
|
||||
|
||||
/*type QuoteDataForm = Omit<IGetQuote_Response_DTO, "items"> & {
|
||||
items: IGetQuote_QuoteItem_Response_DTO;
|
||||
};*/
|
||||
|
||||
type QuoteDataForm = IGetQuote_Response_DTO;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@ -37,15 +33,6 @@ export const QuoteEdit = () => {
|
||||
);
|
||||
const [quoteLanguage, setQuoteLanguage] = useState<Language>(Language.createDefaultCode().object);
|
||||
|
||||
/*const { data: userIdentity } = useGetIdentity();
|
||||
console.log(userIdentity);
|
||||
|
||||
const { flag } = useLocalization({
|
||||
locale: userIdentity?.language ?? "es-es",
|
||||
});
|
||||
|
||||
console.log(flag);*/
|
||||
|
||||
const { useOne, useUpdate } = useQuotes();
|
||||
|
||||
const { data, status, error: queryError } = useOne(quoteId);
|
||||
@ -159,106 +146,6 @@ export const QuoteEdit = () => {
|
||||
});
|
||||
};
|
||||
|
||||
/* useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { unsubscribe } = watch((_, { name, type }) => {
|
||||
const value = getValues();
|
||||
|
||||
console.log(name);
|
||||
|
||||
if (name) {
|
||||
if (name === "currency_code") {
|
||||
setQuoteCurrency(
|
||||
CurrencyData.createFromCode(value.currency_code ?? CurrencyData.DEFAULT_CURRENCY_CODE)
|
||||
.object
|
||||
);
|
||||
}
|
||||
|
||||
if (name === "lang_code") {
|
||||
setQuoteLanguage(
|
||||
Language.createFromCode(value.lang_code ?? Language.DEFAULT_LANGUAGE_CODE).object
|
||||
);
|
||||
}
|
||||
|
||||
if (name === "items") {
|
||||
console.log(">> Recalculo todas las líneas");
|
||||
const { items } = value;
|
||||
|
||||
let quoteSubtotal = MoneyValue.create({
|
||||
amount: 0,
|
||||
scale: 4,
|
||||
}).object;
|
||||
|
||||
// Recálculo líneas
|
||||
items &&
|
||||
items.map((item, index) => {
|
||||
const itemTotals = calculateQuoteItemTotals(item);
|
||||
quoteSubtotal = quoteSubtotal.add(itemTotals.totalPrice);
|
||||
setValue(`items.${index}.subtotal_price`, itemTotals.subtotalPrice.toObject());
|
||||
setValue(`items.${index}.total_price`, itemTotals.totalPrice.toObject());
|
||||
});
|
||||
|
||||
// Recálculo completo
|
||||
setValue("subtotal_price", quoteSubtotal.convertScale(2).toObject());
|
||||
}
|
||||
|
||||
if (name.endsWith("quantity") || name.endsWith("unit_price") || name.endsWith("discount")) {
|
||||
console.group(">>>>>>>>>>>>>");
|
||||
|
||||
const { items } = value;
|
||||
|
||||
const [, indexString, fieldName] = String(name).split(".");
|
||||
const index = parseInt(indexString);
|
||||
|
||||
console.group(">> Voy a recalcular la línea ", index, items[index]);
|
||||
|
||||
const itemTotals_1 = calculateQuoteItemTotals(items[index]);
|
||||
setValue(`items.${index}.subtotal_price`, itemTotals_1.subtotalPrice.toObject());
|
||||
setValue(`items.${index}.total_price`, itemTotals_1.totalPrice.toObject());
|
||||
|
||||
console.log(">> Total de la línea -> ", index, itemTotals_1.subtotalPrice.toObject());
|
||||
|
||||
console.groupEnd();
|
||||
|
||||
// Recálculo completo
|
||||
let quoteSubtotal = MoneyValue.create({
|
||||
amount: 0,
|
||||
scale: 4,
|
||||
}).object;
|
||||
|
||||
console.group(">> Recalculo todas las líneas");
|
||||
|
||||
items &&
|
||||
items.map((item, itemIndex) => {
|
||||
const itemTotals_2 = calculateQuoteItemTotals(item);
|
||||
|
||||
console.log(
|
||||
">> Recalculo la linea ",
|
||||
itemIndex,
|
||||
itemTotals_2.subtotalPrice.toObject()
|
||||
);
|
||||
|
||||
quoteSubtotal = quoteSubtotal.add(itemTotals_2.totalPrice);
|
||||
setValue(`items.${itemIndex}.subtotal_price`, itemTotals_2.subtotalPrice.toObject());
|
||||
setValue(`items.${itemIndex}.total_price`, itemTotals_2.totalPrice.toObject());
|
||||
});
|
||||
|
||||
console.log(
|
||||
">> Gruardo el total en la cabecera ",
|
||||
quoteSubtotal.convertScale(2).toObject()
|
||||
);
|
||||
|
||||
// Recálculo completo
|
||||
setValue("subtotal_price", quoteSubtotal.convertScale(2).toObject());
|
||||
console.groupEnd();
|
||||
|
||||
console.groupEnd();
|
||||
}
|
||||
}
|
||||
});
|
||||
return () => unsubscribe();
|
||||
}, [watch, getValues, setValue]);*/
|
||||
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { unsubscribe } = watch((_, { name, type }) => {
|
||||
|
||||
@ -95,8 +95,9 @@
|
||||
"subtitle": "",
|
||||
"tabs": {
|
||||
"all": "All",
|
||||
"emitted": "Emitted",
|
||||
"draft": "Draft",
|
||||
"archived": "Archive"
|
||||
"archived": "Archived"
|
||||
},
|
||||
"columns": {
|
||||
"date": "Date",
|
||||
|
||||
@ -95,8 +95,8 @@
|
||||
"subtitle": "",
|
||||
"tabs": {
|
||||
"all": "Todas",
|
||||
"draft": "Borradores",
|
||||
"emitted": "Emitidas",
|
||||
"draft": "Borradores",
|
||||
"archived": "Archivadas"
|
||||
},
|
||||
"columns": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user