.
This commit is contained in:
parent
d4489ef15b
commit
a845edb9c7
@ -202,13 +202,6 @@ export function SortableDataTable({ columns, data, actions }: SortableDataTableP
|
||||
updateItem: (rowIndex: number, rowData: unknown, fieldName: string, value: unknown) => {
|
||||
// Skip page index reset until after next rerender
|
||||
// skipAutoResetPageIndex();
|
||||
console.log({
|
||||
rowIndex,
|
||||
rowData,
|
||||
fieldName,
|
||||
value,
|
||||
});
|
||||
|
||||
actions.update(rowIndex, { ...rowData, [`${fieldName}`]: value });
|
||||
},
|
||||
},
|
||||
|
||||
@ -7,14 +7,20 @@ import {
|
||||
import { DataTableProvider } from "@/lib/hooks";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/ui";
|
||||
import { CurrencyData, Quantity } from "@shared/contexts";
|
||||
import { CurrencyData, Language, Quantity } from "@shared/contexts";
|
||||
import { t } from "i18next";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useFieldArray, useFormContext } from "react-hook-form";
|
||||
import { useDetailColumns } from "../../hooks";
|
||||
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 { fields, ...fieldActions } = useFieldArray({
|
||||
@ -75,6 +81,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
||||
<FormCurrencyField
|
||||
variant='outline'
|
||||
currency={currency}
|
||||
language={language}
|
||||
scale={4}
|
||||
className='text-right'
|
||||
{...register(`items.${index}.unit_price`)}
|
||||
@ -94,6 +101,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
||||
<FormCurrencyField
|
||||
variant='outline'
|
||||
currency={currency}
|
||||
language={language}
|
||||
scale={4}
|
||||
readOnly
|
||||
className='text-right'
|
||||
@ -132,6 +140,7 @@ export const QuoteDetailsCardEditor = ({ currency }: { currency: CurrencyData })
|
||||
<FormCurrencyField
|
||||
variant='outline'
|
||||
currency={currency}
|
||||
language={language}
|
||||
scale={4}
|
||||
readOnly
|
||||
className='font-semibold text-right'
|
||||
|
||||
@ -102,7 +102,7 @@ export const QuoteGeneralCardEditor = () => {
|
||||
required
|
||||
label={t("quotes.form_fields.lang_code.label")}
|
||||
description={t("quotes.form_fields.lang_code.desc")}
|
||||
disabled={formState.disabled}
|
||||
//disabled={formState.disabled}
|
||||
placeholder={t("quotes.form_fields.lang_code.placeholder")}
|
||||
{...register("lang_code", {
|
||||
required: true,
|
||||
@ -112,7 +112,7 @@ export const QuoteGeneralCardEditor = () => {
|
||||
required
|
||||
label={t("quotes.form_fields.currency_code.label")}
|
||||
description={t("quotes.form_fields.currency_code.desc")}
|
||||
disabled={formState.disabled}
|
||||
//disabled={formState.disabled}
|
||||
placeholder={t("quotes.form_fields.currency_code.placeholder")}
|
||||
{...register("currency_code", {
|
||||
required: true,
|
||||
|
||||
@ -44,8 +44,6 @@ export const QuoteCreate = () => {
|
||||
}, [watch, setWarnWhen]);
|
||||
|
||||
const onSubmit: SubmitHandler<QuoteDataForm> = async (formData) => {
|
||||
console.log(JSON.stringify(formData));
|
||||
|
||||
try {
|
||||
setWarnWhen(false);
|
||||
mutate(formData, {
|
||||
|
||||
@ -8,7 +8,7 @@ import {
|
||||
import { calculateItemTotals } from "@/lib/calc";
|
||||
import { useUrlId } from "@/lib/hooks/useUrlId";
|
||||
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 { useEffect, useState } from "react";
|
||||
import { SubmitHandler, useForm } from "react-hook-form";
|
||||
@ -23,9 +23,11 @@ interface QuoteDataForm extends IUpdateQuote_Request_DTO {}
|
||||
export const QuoteEdit = () => {
|
||||
const navigate = useNavigate();
|
||||
const quoteId = useUrlId();
|
||||
|
||||
const [quoteCurrency, setQuoteCurrency] = useState<CurrencyData>(
|
||||
CurrencyData.createDefaultCode().object
|
||||
);
|
||||
const [quoteLanguage, setQuoteLanguage] = useState<Language>(Language.createDefaultCode().object);
|
||||
|
||||
/*const { data: userIdentity } = useGetIdentity();
|
||||
console.log(userIdentity);
|
||||
@ -130,16 +132,23 @@ export const QuoteEdit = () => {
|
||||
const { unsubscribe } = watch((_, { name, type }) => {
|
||||
const value = getValues();
|
||||
|
||||
console.log(value);
|
||||
console.log("USEEFFECT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
console.log(name);
|
||||
|
||||
if (name) {
|
||||
if (name === "currency_code") {
|
||||
setQuoteCurrency(
|
||||
CurrencyData.createFromCode(value.lang_code ?? CurrencyData.DEFAULT_CURRENCY_CODE)
|
||||
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") {
|
||||
const { items } = value;
|
||||
let quoteSubtotal = MoneyValue.create().object;
|
||||
@ -232,7 +241,7 @@ export const QuoteEdit = () => {
|
||||
<QuoteGeneralCardEditor />
|
||||
</TabsContent>
|
||||
<TabsContent value='items'>
|
||||
<QuoteDetailsCardEditor currency={quoteCurrency} />
|
||||
<QuoteDetailsCardEditor currency={quoteCurrency} language={quoteLanguage} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='history'></TabsContent>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
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 * as React from "react";
|
||||
import CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field";
|
||||
@ -38,6 +38,7 @@ export type FormCurrencyFieldProps<
|
||||
UseControllerProps<TFieldValues, TName> &
|
||||
VariantProps<typeof formCurrencyFieldVariants> & {
|
||||
currency: CurrencyData;
|
||||
language: Language;
|
||||
scale: number;
|
||||
};
|
||||
|
||||
@ -56,15 +57,16 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
|
||||
readOnly,
|
||||
scale,
|
||||
currency,
|
||||
language,
|
||||
variant,
|
||||
} = props;
|
||||
|
||||
const { control } = useFormContext();
|
||||
|
||||
const [oldValue, setOldValue] = React.useState<string>("");
|
||||
const [inputValue, setInputValue] = React.useState<string>("");
|
||||
|
||||
const transform = {
|
||||
input: (value: any) => {
|
||||
input: (value: MoneyValueObject) => {
|
||||
if (typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
@ -75,19 +77,13 @@ export const FormCurrencyField = React.forwardRef<HTMLInputElement, FormCurrency
|
||||
throw moneyOrError.error;
|
||||
}
|
||||
|
||||
let result = moneyOrError.object.toString();
|
||||
console.log(result, oldValue);
|
||||
|
||||
if (oldValue.endsWith(",")) {
|
||||
result = result.replace(/.0$/, ",");
|
||||
}
|
||||
|
||||
return result;
|
||||
const result = moneyOrError.object.toString();
|
||||
return inputValue.endsWith(",") ? result.replace(/.0$/, ",") : result;
|
||||
},
|
||||
output: (value: string | undefined, name?: string, values?: CurrencyInputOnChangeValues) => {
|
||||
const { value: amount } = values ?? { value: null };
|
||||
|
||||
setOldValue(amount ?? "");
|
||||
setInputValue(amount ?? "");
|
||||
|
||||
const moneyOrError = MoneyValue.createFromFormattedValue(amount, currency.code);
|
||||
if (moneyOrError.isFailure) {
|
||||
|
||||
@ -2,7 +2,7 @@ import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
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 CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field";
|
||||
import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form";
|
||||
@ -63,8 +63,10 @@ export const FormPercentageField = React.forwardRef<
|
||||
|
||||
const { control } = useFormContext();
|
||||
|
||||
const [inputValue, setInputValue] = React.useState<string>("");
|
||||
|
||||
const transform = {
|
||||
input: (value: any) => {
|
||||
input: (value: PercentageObject) => {
|
||||
if (typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
@ -74,12 +76,14 @@ export const FormPercentageField = React.forwardRef<
|
||||
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) => {
|
||||
console.log(values);
|
||||
const { value: amount } = values ?? { value: null };
|
||||
|
||||
setInputValue(amount ?? "");
|
||||
|
||||
const percentageOrError = Percentage.createFromFormattedValue(amount);
|
||||
|
||||
if (percentageOrError.isFailure) {
|
||||
|
||||
@ -2,7 +2,7 @@ import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
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 CurrencyInput, { CurrencyInputOnChangeValues } from "react-currency-input-field";
|
||||
import { FieldPath, FieldValues, UseControllerProps, useFormContext } from "react-hook-form";
|
||||
@ -60,8 +60,10 @@ export const FormQuantityField = React.forwardRef<HTMLInputElement, FormQuantity
|
||||
|
||||
const { control } = useFormContext();
|
||||
|
||||
const [inputValue, setInputValue] = React.useState<string>("");
|
||||
|
||||
const transform = {
|
||||
input: (value: any) => {
|
||||
input: (value: QuantityObject) => {
|
||||
if (typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
@ -71,11 +73,14 @@ export const FormQuantityField = React.forwardRef<HTMLInputElement, FormQuantity
|
||||
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) => {
|
||||
const { value: amount } = values ?? { value: null };
|
||||
|
||||
setInputValue(amount ?? "");
|
||||
|
||||
const quantityOrError = Quantity.createFromFormattedValue(amount);
|
||||
if (quantityOrError.isFailure) {
|
||||
throw quantityOrError.error;
|
||||
|
||||
@ -33,7 +33,6 @@ export const UserButton = () => {
|
||||
},
|
||||
});
|
||||
const { data, status } = useGetProfile();
|
||||
console.log(data, status);
|
||||
|
||||
const openUserMenu = (event: SyntheticEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
@ -15,7 +15,6 @@ export const ProtectedRoute = ({ children }: ProctectRouteProps) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (profileStatus.isSuccess && i18n.language !== profile?.lang_code) {
|
||||
console.log(profile);
|
||||
i18n.changeLanguage(profile?.lang_code);
|
||||
}
|
||||
}, [profile, profileStatus, i18n]);
|
||||
|
||||
@ -53,7 +53,6 @@ export class RuleValidator {
|
||||
public static validateFnc(ruleFnc: (value: any) => any) {
|
||||
return (value: any, helpers) => {
|
||||
const result = ruleFnc(value);
|
||||
console.log(value);
|
||||
return result.isSuccess
|
||||
? value
|
||||
: helpers.message({
|
||||
|
||||
@ -116,7 +116,6 @@ describe("Quantity Value Object", () => {
|
||||
const quantity = Quantity.create({ amount: 5, scale: 2 }).object;
|
||||
|
||||
const incrementedQuantity = quantity.increment().object;
|
||||
console.log(quantity.toNumber());
|
||||
|
||||
expect(incrementedQuantity.toNumber()).toBe(0.06);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user