.
This commit is contained in:
parent
740f5fd238
commit
d4489ef15b
@ -41,7 +41,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
|||||||
header: () => (
|
header: () => (
|
||||||
<div className='text-right'>{t("quotes.form_fields.items.quantity.label")}</div>
|
<div className='text-right'>{t("quotes.form_fields.items.quantity.label")}</div>
|
||||||
),
|
),
|
||||||
size: 8,
|
size: 6,
|
||||||
cell: ({ row: { index } }) => {
|
cell: ({ row: { index } }) => {
|
||||||
return (
|
return (
|
||||||
<FormQuantityField
|
<FormQuantityField
|
||||||
@ -59,7 +59,9 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
|||||||
header: t("quotes.form_fields.items.description.label"),
|
header: t("quotes.form_fields.items.description.label"),
|
||||||
size: 24,
|
size: 24,
|
||||||
cell: ({ row: { index } }) => {
|
cell: ({ row: { index } }) => {
|
||||||
return <FormTextField autoSize {...register(`items.${index}.description`)} />;
|
return (
|
||||||
|
<FormTextField variant='outline' autoSize {...register(`items.${index}.description`)} />
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -80,29 +82,30 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/*{
|
{
|
||||||
id: "subtotal_price" as const,
|
id: "subtotal_price" as const,
|
||||||
accessorKey: "subtotal_price",
|
accessorKey: "subtotal_price",
|
||||||
header: () => (
|
header: () => (
|
||||||
<div className='text-right'>{t("quotes.form_fields.items.subtotal_price.label")}</div>
|
<div className='text-right'>{t("quotes.form_fields.items.subtotal_price.label")}</div>
|
||||||
),
|
),
|
||||||
|
size: 12,
|
||||||
cell: ({ row: { index }, column: { id } }) => {
|
cell: ({ row: { index }, column: { id } }) => {
|
||||||
return (
|
return (
|
||||||
<FormCurrencyField
|
<FormCurrencyField
|
||||||
variant='outline'
|
variant='outline'
|
||||||
currency={currency}
|
currency={currency}
|
||||||
scale={4}
|
scale={4}
|
||||||
disabled
|
readOnly
|
||||||
className='text-right'
|
className='text-right'
|
||||||
{...register(`items.${index}.subtotal_price`)}
|
{...register(`items.${index}.subtotal_price`)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},*/
|
},
|
||||||
{
|
{
|
||||||
id: "discount" as const,
|
id: "discount" as const,
|
||||||
accessorKey: "discount",
|
accessorKey: "discount",
|
||||||
size: 8,
|
size: 6,
|
||||||
header: () => (
|
header: () => (
|
||||||
<div className='text-right'>{t("quotes.form_fields.items.discount.label")}</div>
|
<div className='text-right'>{t("quotes.form_fields.items.discount.label")}</div>
|
||||||
),
|
),
|
||||||
@ -117,25 +120,26 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/*{
|
{
|
||||||
id: "total_price" as const,
|
id: "total_price" as const,
|
||||||
accessorKey: "total_price",
|
accessorKey: "total_price",
|
||||||
header: () => (
|
header: () => (
|
||||||
<div className='text-right'>{t("quotes.form_fields.items.total_price.label")}</div>
|
<div className='text-right'>{t("quotes.form_fields.items.total_price.label")}</div>
|
||||||
),
|
),
|
||||||
|
size: 12,
|
||||||
cell: ({ row: { index }, column: { id } }) => {
|
cell: ({ row: { index }, column: { id } }) => {
|
||||||
return (
|
return (
|
||||||
<FormCurrencyField
|
<FormCurrencyField
|
||||||
variant='outline'
|
variant='outline'
|
||||||
currency={currency}
|
currency={currency}
|
||||||
scale={4}
|
scale={4}
|
||||||
disabled
|
readOnly
|
||||||
className='text-right'
|
className='font-semibold text-right'
|
||||||
{...register(`items.${index}.total_price`)}
|
{...register(`items.${index}.total_price`)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},*/
|
},
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
enableDragHandleColumn: true,
|
enableDragHandleColumn: true,
|
||||||
@ -191,6 +195,8 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
|||||||
const defaultLayout = [265, 440, 655];
|
const defaultLayout = [265, 440, 655];
|
||||||
const navCollapsedSize = 4;
|
const navCollapsedSize = 4;
|
||||||
|
|
||||||
|
return <SortableDataTable actions={fieldActions} columns={columns} data={fields} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResizablePanelGroup
|
<ResizablePanelGroup
|
||||||
direction='horizontal'
|
direction='horizontal'
|
||||||
@ -216,7 +222,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
|||||||
<ResizableHandle withHandle className='mx-3' />
|
<ResizableHandle withHandle className='mx-3' />
|
||||||
<ResizablePanel defaultSize={defaultLayout[1]} minSize={10}>
|
<ResizablePanel defaultSize={defaultLayout[1]} minSize={10}>
|
||||||
<DataTableProvider syncWithLocation={false}>
|
<DataTableProvider syncWithLocation={false}>
|
||||||
{/*<CatalogPickerDataTable onClick={handleInsertArticle} />*/}
|
<CatalogPickerDataTable onClick={handleInsertArticle} />
|
||||||
</DataTableProvider>
|
</DataTableProvider>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
</ResizablePanelGroup>
|
</ResizablePanelGroup>
|
||||||
|
|||||||
@ -68,11 +68,12 @@ export const QuoteEdit = () => {
|
|||||||
scale: 2,
|
scale: 2,
|
||||||
currency_code: data?.currency_code,
|
currency_code: data?.currency_code,
|
||||||
},
|
},
|
||||||
/*items: [
|
items: [
|
||||||
{
|
{
|
||||||
|
description: "",
|
||||||
quantity: {
|
quantity: {
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
scale: 2,
|
scale: 0,
|
||||||
},
|
},
|
||||||
subtotal_price: {
|
subtotal_price: {
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
@ -81,7 +82,7 @@ export const QuoteEdit = () => {
|
|||||||
},
|
},
|
||||||
discount: {
|
discount: {
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
scale: 0,
|
scale: 2,
|
||||||
},
|
},
|
||||||
total_price: {
|
total_price: {
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
@ -89,7 +90,7 @@ export const QuoteEdit = () => {
|
|||||||
currency_code: data?.currency_code,
|
currency_code: data?.currency_code,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],*/
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -129,6 +130,8 @@ export const QuoteEdit = () => {
|
|||||||
const { unsubscribe } = watch((_, { name, type }) => {
|
const { unsubscribe } = watch((_, { name, type }) => {
|
||||||
const value = getValues();
|
const value = getValues();
|
||||||
|
|
||||||
|
console.log(value);
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
if (name === "currency_code") {
|
if (name === "currency_code") {
|
||||||
setQuoteCurrency(
|
setQuoteCurrency(
|
||||||
@ -146,8 +149,6 @@ export const QuoteEdit = () => {
|
|||||||
items.map((item, index) => {
|
items.map((item, index) => {
|
||||||
const itemTotals = calculateItemTotals(item);
|
const itemTotals = calculateItemTotals(item);
|
||||||
|
|
||||||
console.log(itemTotals?.quantity.toObject());
|
|
||||||
|
|
||||||
if (itemTotals === null) {
|
if (itemTotals === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,8 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
|
|||||||
|
|
||||||
const { control } = useFormContext();
|
const { control } = useFormContext();
|
||||||
|
|
||||||
|
const [oldValue, setOldValue] = React.useState<string>("");
|
||||||
|
|
||||||
const transform = {
|
const transform = {
|
||||||
input: (value: any) => {
|
input: (value: any) => {
|
||||||
if (typeof value !== "object") {
|
if (typeof value !== "object") {
|
||||||
@ -73,11 +75,20 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
|
|||||||
throw moneyOrError.error;
|
throw moneyOrError.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return moneyOrError.object.toString();
|
let result = moneyOrError.object.toString();
|
||||||
|
console.log(result, oldValue);
|
||||||
|
|
||||||
|
if (oldValue.endsWith(",")) {
|
||||||
|
result = result.replace(/.0$/, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
output: (value: string | undefined, name?: string, values?: CurrencyInputOnChangeValues) => {
|
output: (value: string | undefined, name?: string, values?: CurrencyInputOnChangeValues) => {
|
||||||
const { value: amount } = values ?? { value: null };
|
const { value: amount } = values ?? { value: null };
|
||||||
|
|
||||||
|
setOldValue(amount ?? "");
|
||||||
|
|
||||||
const moneyOrError = MoneyValue.createFromFormattedValue(amount, currency.code);
|
const moneyOrError = MoneyValue.createFromFormattedValue(amount, currency.code);
|
||||||
if (moneyOrError.isFailure) {
|
if (moneyOrError.isFailure) {
|
||||||
throw moneyOrError.error;
|
throw moneyOrError.error;
|
||||||
@ -126,6 +137,7 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
{description && <FormDescription>{description}</FormDescription>}
|
{description && <FormDescription>{description}</FormDescription>}
|
||||||
<FormErrorMessage />
|
<FormErrorMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { FormControl, FormDescription, FormField, FormItem, Input, InputProps } from "@/ui";
|
import { FormControl, FormDescription, FormField, FormItem, Input, InputProps } from "@/ui";
|
||||||
|
|
||||||
import { cva } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { createElement } from "react";
|
import { createElement } from "react";
|
||||||
import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form";
|
import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form";
|
||||||
@ -9,7 +9,7 @@ import { FormErrorMessage } from "./FormErrorMessage";
|
|||||||
import { FormLabel, FormLabelProps } from "./FormLabel";
|
import { FormLabel, FormLabelProps } from "./FormLabel";
|
||||||
import { FormInputProps, FormInputWithIconProps } from "./FormProps";
|
import { FormInputProps, FormInputWithIconProps } from "./FormProps";
|
||||||
|
|
||||||
const FormTextFieldVariants = cva("", {
|
const formTextFieldVariants = cva("", {
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "",
|
default: "",
|
||||||
@ -31,7 +31,8 @@ export type FormTextFieldProps<
|
|||||||
FormInputProps &
|
FormInputProps &
|
||||||
Partial<FormLabelProps> &
|
Partial<FormLabelProps> &
|
||||||
FormInputWithIconProps &
|
FormInputWithIconProps &
|
||||||
UseControllerProps<TFieldValues, TName>;
|
UseControllerProps<TFieldValues, TName> &
|
||||||
|
VariantProps<typeof formTextFieldVariants>;
|
||||||
|
|
||||||
export const FormTextField = React.forwardRef<HTMLInputElement, FormTextFieldProps>(
|
export const FormTextField = React.forwardRef<HTMLInputElement, FormTextFieldProps>(
|
||||||
(props, ref) => {
|
(props, ref) => {
|
||||||
@ -95,7 +96,7 @@ export const FormTextField = React.forwardRef<HTMLInputElement, FormTextFieldPro
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
className={cn(
|
className={cn(
|
||||||
fieldState.error ? "border-destructive focus-visible:ring-destructive" : "",
|
fieldState.error ? "border-destructive focus-visible:ring-destructive" : "",
|
||||||
FormTextFieldVariants({ variant, className })
|
formTextFieldVariants({ variant, className })
|
||||||
)}
|
)}
|
||||||
{...field}
|
{...field}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -12,8 +12,14 @@ export const calculateItemTotals = (item: {
|
|||||||
discount: Percentage;
|
discount: Percentage;
|
||||||
totalPrice: MoneyValue;
|
totalPrice: MoneyValue;
|
||||||
} | null => {
|
} | null => {
|
||||||
|
console.log(item);
|
||||||
|
|
||||||
const { quantity: quantity_dto, unit_price: unit_price_dto, discount: discount_dto } = item;
|
const { quantity: quantity_dto, unit_price: unit_price_dto, discount: discount_dto } = item;
|
||||||
|
|
||||||
|
if (quantity_dto === "" || unit_price_dto === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const quantityOrError = Quantity.create(quantity_dto);
|
const quantityOrError = Quantity.create(quantity_dto);
|
||||||
if (quantityOrError.isFailure) {
|
if (quantityOrError.isFailure) {
|
||||||
throw quantityOrError.error;
|
throw quantityOrError.error;
|
||||||
|
|||||||
@ -141,8 +141,6 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
scale = defaultMoneyValueProps.scale,
|
scale = defaultMoneyValueProps.scale,
|
||||||
} = props || {};
|
} = props || {};
|
||||||
|
|
||||||
console.log(props, { amount, currencyCode, scale });
|
|
||||||
|
|
||||||
const validationResult = MoneyValue.validate(amount, options);
|
const validationResult = MoneyValue.validate(amount, options);
|
||||||
|
|
||||||
if (validationResult.isFailure) {
|
if (validationResult.isFailure) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user