This commit is contained in:
David Arranz 2024-07-17 13:03:02 +02:00
parent d4489ef15b
commit a845edb9c7
12 changed files with 50 additions and 40 deletions

View File

@ -202,13 +202,6 @@ export function SortableDataTable({ columns, data, actions }: SortableDataTableP
updateItem: (rowIndex: number, rowData: unknown, fieldName: string, value: unknown) => { updateItem: (rowIndex: number, rowData: unknown, fieldName: string, value: unknown) => {
// Skip page index reset until after next rerender // Skip page index reset until after next rerender
// skipAutoResetPageIndex(); // skipAutoResetPageIndex();
console.log({
rowIndex,
rowData,
fieldName,
value,
});
actions.update(rowIndex, { ...rowData, [`${fieldName}`]: value }); actions.update(rowIndex, { ...rowData, [`${fieldName}`]: value });
}, },
}, },

View File

@ -7,14 +7,20 @@ import {
import { DataTableProvider } from "@/lib/hooks"; import { DataTableProvider } from "@/lib/hooks";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/ui"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/ui";
import { CurrencyData, Quantity } from "@shared/contexts"; import { CurrencyData, Language, Quantity } from "@shared/contexts";
import { t } from "i18next"; import { t } from "i18next";
import { useCallback, useState } from "react"; import { useCallback, useState } from "react";
import { useFieldArray, useFormContext } from "react-hook-form"; import { useFieldArray, useFormContext } from "react-hook-form";
import { useDetailColumns } from "../../hooks"; import { useDetailColumns } from "../../hooks";
import { SortableDataTable } from "../SortableDataTable"; import { SortableDataTable } from "../SortableDataTable";
export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData }) => { export const QuoteDetailsCardEditor = ({
currency,
language,
}: {
currency: CurrencyData;
language: Language;
}) => {
const { control, register, getValues } = useFormContext(); const { control, register, getValues } = useFormContext();
const { fields, ...fieldActions } = useFieldArray({ const { fields, ...fieldActions } = useFieldArray({
@ -75,6 +81,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
<FormCurrencyField <FormCurrencyField
variant='outline' variant='outline'
currency={currency} currency={currency}
language={language}
scale={4} scale={4}
className='text-right' className='text-right'
{...register(`items.${index}.unit_price`)} {...register(`items.${index}.unit_price`)}
@ -94,6 +101,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
<FormCurrencyField <FormCurrencyField
variant='outline' variant='outline'
currency={currency} currency={currency}
language={language}
scale={4} scale={4}
readOnly readOnly
className='text-right' className='text-right'
@ -132,6 +140,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
<FormCurrencyField <FormCurrencyField
variant='outline' variant='outline'
currency={currency} currency={currency}
language={language}
scale={4} scale={4}
readOnly readOnly
className='font-semibold text-right' className='font-semibold text-right'

View File

@ -102,7 +102,7 @@ export const QuoteGeneralCardEditor = () => {
required required
label={t("quotes.form_fields.lang_code.label")} label={t("quotes.form_fields.lang_code.label")}
description={t("quotes.form_fields.lang_code.desc")} description={t("quotes.form_fields.lang_code.desc")}
disabled={formState.disabled} //disabled={formState.disabled}
placeholder={t("quotes.form_fields.lang_code.placeholder")} placeholder={t("quotes.form_fields.lang_code.placeholder")}
{...register("lang_code", { {...register("lang_code", {
required: true, required: true,
@ -112,7 +112,7 @@ export const QuoteGeneralCardEditor = () => {
required required
label={t("quotes.form_fields.currency_code.label")} label={t("quotes.form_fields.currency_code.label")}
description={t("quotes.form_fields.currency_code.desc")} description={t("quotes.form_fields.currency_code.desc")}
disabled={formState.disabled} //disabled={formState.disabled}
placeholder={t("quotes.form_fields.currency_code.placeholder")} placeholder={t("quotes.form_fields.currency_code.placeholder")}
{...register("currency_code", { {...register("currency_code", {
required: true, required: true,

View File

@ -44,8 +44,6 @@ export const QuoteCreate = () => {
}, [watch, setWarnWhen]); }, [watch, setWarnWhen]);
const onSubmit: SubmitHandler<QuoteDataForm> = async (formData) => { const onSubmit: SubmitHandler<QuoteDataForm> = async (formData) => {
console.log(JSON.stringify(formData));
try { try {
setWarnWhen(false); setWarnWhen(false);
mutate(formData, { mutate(formData, {

View File

@ -8,7 +8,7 @@ import {
import { calculateItemTotals } from "@/lib/calc"; import { calculateItemTotals } from "@/lib/calc";
import { useUrlId } from "@/lib/hooks/useUrlId"; import { useUrlId } from "@/lib/hooks/useUrlId";
import { Badge, Button, Form, Tabs, TabsContent, TabsList, TabsTrigger } from "@/ui"; import { Badge, Button, Form, Tabs, TabsContent, TabsList, TabsTrigger } from "@/ui";
import { CurrencyData, IUpdateQuote_Request_DTO, MoneyValue } from "@shared/contexts"; import { CurrencyData, IUpdateQuote_Request_DTO, Language, MoneyValue } from "@shared/contexts";
import { t } from "i18next"; import { t } from "i18next";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { SubmitHandler, useForm } from "react-hook-form"; import { SubmitHandler, useForm } from "react-hook-form";
@ -23,9 +23,11 @@ interface QuoteDataForm extends IUpdateQuote_Request_DTO {}
export const QuoteEdit = () => { export const QuoteEdit = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const quoteId = useUrlId(); const quoteId = useUrlId();
const [quoteCurrency, setQuoteCurrency] = useState<CurrencyData>( const [quoteCurrency, setQuoteCurrency] = useState<CurrencyData>(
CurrencyData.createDefaultCode().object CurrencyData.createDefaultCode().object
); );
const [quoteLanguage, setQuoteLanguage] = useState<Language>(Language.createDefaultCode().object);
/*const { data: userIdentity } = useGetIdentity(); /*const { data: userIdentity } = useGetIdentity();
console.log(userIdentity); console.log(userIdentity);
@ -130,16 +132,23 @@ export const QuoteEdit = () => {
const { unsubscribe } = watch((_, { name, type }) => { const { unsubscribe } = watch((_, { name, type }) => {
const value = getValues(); const value = getValues();
console.log(value); console.log("USEEFFECT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
console.log(name);
if (name) { if (name) {
if (name === "currency_code") { if (name === "currency_code") {
setQuoteCurrency( setQuoteCurrency(
CurrencyData.createFromCode(value.lang_code ?? CurrencyData.DEFAULT_CURRENCY_CODE) CurrencyData.createFromCode(value.currency_code ?? CurrencyData.DEFAULT_CURRENCY_CODE)
.object .object
); );
} }
if (name === "lang_code") {
setQuoteLanguage(
Language.createFromCode(value.lang_code ?? Language.DEFAULT_LANGUAGE_CODE).object
);
}
if (name === "items") { if (name === "items") {
const { items } = value; const { items } = value;
let quoteSubtotal = MoneyValue.create().object; let quoteSubtotal = MoneyValue.create().object;
@ -232,7 +241,7 @@ export const QuoteEdit = () => {
<QuoteGeneralCardEditor /> <QuoteGeneralCardEditor />
</TabsContent> </TabsContent>
<TabsContent value='items'> <TabsContent value='items'>
<QuoteDetailsCardEditor currency={quoteCurrency} /> <QuoteDetailsCardEditor currency={quoteCurrency} language={quoteLanguage} />
</TabsContent> </TabsContent>
<TabsContent value='history'></TabsContent> <TabsContent value='history'></TabsContent>

View File

@ -1,6 +1,6 @@
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { FormControl, FormDescription, FormField, FormItem, InputProps } from "@/ui"; import { FormControl, FormDescription, FormField, FormItem, InputProps } from "@/ui";
import { CurrencyData, MoneyValue } from "@shared/contexts"; import { CurrencyData, Language, MoneyValue, MoneyValueObject } from "@shared/contexts";
import { cva, type VariantProps } from "class-variance-authority"; import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react"; import * as React from "react";
import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field"; import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field";
@ -38,6 +38,7 @@ export type FormCurrencyFieldProps<
UseControllerProps<TFieldValues, TName> & UseControllerProps<TFieldValues, TName> &
VariantProps<typeof formCurrencyFieldVariants> & { VariantProps<typeof formCurrencyFieldVariants> & {
currency: CurrencyData; currency: CurrencyData;
language: Language;
scale: number; scale: number;
}; };
@ -56,15 +57,16 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
readOnly, readOnly,
scale, scale,
currency, currency,
language,
variant, variant,
} = props; } = props;
const { control } = useFormContext(); const { control } = useFormContext();
const [oldValue, setOldValue] = React.useState<string>(""); const [inputValue, setInputValue] = React.useState<string>("");
const transform = { const transform = {
input: (value: any) => { input: (value: MoneyValueObject) => {
if (typeof value !== "object") { if (typeof value !== "object") {
return value; return value;
} }
@ -75,19 +77,13 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
throw moneyOrError.error; throw moneyOrError.error;
} }
let result = moneyOrError.object.toString(); const result = moneyOrError.object.toString();
console.log(result, oldValue); return inputValue.endsWith(",") ? result.replace(/.0$/, ",") : result;
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 ?? ""); setInputValue(amount ?? "");
const moneyOrError = MoneyValue.createFromFormattedValue(amount, currency.code); const moneyOrError = MoneyValue.createFromFormattedValue(amount, currency.code);
if (moneyOrError.isFailure) { if (moneyOrError.isFailure) {

View File

@ -2,7 +2,7 @@ import * as React from "react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { FormControl, FormDescription, FormField, FormItem, InputProps } from "@/ui"; import { FormControl, FormDescription, FormField, FormItem, InputProps } from "@/ui";
import { Percentage } from "@shared/contexts"; import { Percentage, PercentageObject } from "@shared/contexts";
import { cva, type VariantProps } from "class-variance-authority"; import { cva, type VariantProps } from "class-variance-authority";
import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field"; import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field";
import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form"; import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form";
@ -63,8 +63,10 @@ export const FormPercentageField = React.forwardRef<
const { control } = useFormContext(); const { control } = useFormContext();
const [inputValue, setInputValue] = React.useState<string>("");
const transform = { const transform = {
input: (value: any) => { input: (value: PercentageObject) => {
if (typeof value !== "object") { if (typeof value !== "object") {
return value; return value;
} }
@ -74,12 +76,14 @@ export const FormPercentageField = React.forwardRef<
throw percentageOrError.error; throw percentageOrError.error;
} }
return percentageOrError.object.toString(); const result = percentageOrError.object.toString();
return inputValue.endsWith(",") ? result.replace(/.0$/, ",") : result;
}, },
output: (value: string | undefined, name?: string, values?: CurrencyInputOnChangeValues) => { output: (value: string | undefined, name?: string, values?: CurrencyInputOnChangeValues) => {
console.log(values);
const { value: amount } = values ?? { value: null }; const { value: amount } = values ?? { value: null };
setInputValue(amount ?? "");
const percentageOrError = Percentage.createFromFormattedValue(amount); const percentageOrError = Percentage.createFromFormattedValue(amount);
if (percentageOrError.isFailure) { if (percentageOrError.isFailure) {

View File

@ -2,7 +2,7 @@ import * as React from "react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { FormControl, FormDescription, FormField, FormItem, InputProps } from "@/ui"; import { FormControl, FormDescription, FormField, FormItem, InputProps } from "@/ui";
import { Quantity } from "@shared/contexts"; import { Quantity, QuantityObject } from "@shared/contexts";
import { cva, type VariantProps } from "class-variance-authority"; import { cva, type VariantProps } from "class-variance-authority";
import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field"; import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field";
import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form"; import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form";
@ -60,8 +60,10 @@ export const FormQuantityField = React.forwardRef<HTMLInputElement, FormQuantity
const { control } = useFormContext(); const { control } = useFormContext();
const [inputValue, setInputValue] = React.useState<string>("");
const transform = { const transform = {
input: (value: any) => { input: (value: QuantityObject) => {
if (typeof value !== "object") { if (typeof value !== "object") {
return value; return value;
} }
@ -71,11 +73,14 @@ export const FormQuantityField = React.forwardRef<HTMLInputElement, FormQuantity
throw quantityOrError.error; throw quantityOrError.error;
} }
return quantityOrError.object.toString(); const result = quantityOrError.object.toString();
return inputValue.endsWith(",") ? result.replace(/.0$/, ",") : 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 };
setInputValue(amount ?? "");
const quantityOrError = Quantity.createFromFormattedValue(amount); const quantityOrError = Quantity.createFromFormattedValue(amount);
if (quantityOrError.isFailure) { if (quantityOrError.isFailure) {
throw quantityOrError.error; throw quantityOrError.error;

View File

@ -33,7 +33,6 @@ export const UserButton = () => {
}, },
}); });
const { data, status } = useGetProfile(); const { data, status } = useGetProfile();
console.log(data, status);
const openUserMenu = (event: SyntheticEvent) => { const openUserMenu = (event: SyntheticEvent) => {
event.preventDefault(); event.preventDefault();

View File

@ -15,7 +15,6 @@ export const ProtectedRoute = ({ children }: ProctectRouteProps) => {
useEffect(() => { useEffect(() => {
if (profileStatus.isSuccess && i18n.language !== profile?.lang_code) { if (profileStatus.isSuccess && i18n.language !== profile?.lang_code) {
console.log(profile);
i18n.changeLanguage(profile?.lang_code); i18n.changeLanguage(profile?.lang_code);
} }
}, [profile, profileStatus, i18n]); }, [profile, profileStatus, i18n]);

View File

@ -53,7 +53,6 @@ export class RuleValidator {
public static validateFnc(ruleFnc: (value: any) => any) { public static validateFnc(ruleFnc: (value: any) => any) {
return (value: any, helpers) => { return (value: any, helpers) => {
const result = ruleFnc(value); const result = ruleFnc(value);
console.log(value);
return result.isSuccess return result.isSuccess
? value ? value
: helpers.message({ : helpers.message({

View File

@ -116,7 +116,6 @@ describe("Quantity Value Object", () => {
const quantity = Quantity.create({ amount: 5, scale: 2 }).object; const quantity = Quantity.create({ amount: 5, scale: 2 }).object;
const incrementedQuantity = quantity.increment().object; const incrementedQuantity = quantity.increment().object;
console.log(quantity.toNumber());
expect(incrementedQuantity.toNumber()).toBe(0.06); expect(incrementedQuantity.toNumber()).toBe(0.06);
}); });