Skip to content

Commit fe6fbd7

Browse files
Merge branch 'dev' into bal-3144
2 parents 0ce2398 + 5e94853 commit fe6fbd7

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

apps/backoffice-v2/src/common/components/organisms/EditableDetailsV2/EditableDetailsV2.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ export const EditableDetailsV2: FunctionComponent<IEditableDetailsV2Props> = ({
5151
<form onSubmit={form.handleSubmit(handleSubmit)}>
5252
<div className={'grid grid-cols-3 gap-x-4 gap-y-6'}>
5353
<legend className={'sr-only'}>{title}</legend>
54-
{filteredFields.map(({ title, path, props }) => {
55-
const originalValue = form.watch(path);
56-
54+
{filteredFields.map(({ title, value, path, props }) => {
5755
return (
5856
<FormField
5957
key={path}
@@ -73,9 +71,9 @@ export const EditableDetailsV2: FunctionComponent<IEditableDetailsV2Props> = ({
7371
pattern={props.pattern}
7472
options={props.options}
7573
isEditable={!config.actions.editing.disabled && props.isEditable}
76-
value={field.value}
74+
value={value}
7775
valueAlias={props.valueAlias}
78-
originalValue={originalValue}
76+
formValue={field.value}
7977
onInputChange={form.setValue}
8078
onOptionChange={field.onChange}
8179
parse={config.parse}

apps/backoffice-v2/src/common/components/organisms/EditableDetailsV2/components/EditableDetailV2/EditableDetailV2.test.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ describe.skip('EditableDetailV2', () => {
2525
[fieldName]: fieldValue,
2626
},
2727
});
28-
const originalValue = form.watch(fieldName);
2928

3029
return (
3130
<Form {...form}>
@@ -39,7 +38,7 @@ describe.skip('EditableDetailV2', () => {
3938
format={undefined}
4039
isEditable={false}
4140
value={fieldValue}
42-
originalValue={originalValue}
41+
formValue={field.value}
4342
onInputChange={form.setValue}
4443
onOptionChange={field.onChange}
4544
parse={{
@@ -74,7 +73,6 @@ describe.skip('EditableDetailV2', () => {
7473
[fieldName]: fieldValue,
7574
},
7675
});
77-
const originalValue = form.watch(fieldName);
7876

7977
return (
8078
<Form {...form}>
@@ -88,7 +86,7 @@ describe.skip('EditableDetailV2', () => {
8886
format={undefined}
8987
isEditable={false}
9088
value={fieldValue}
91-
originalValue={originalValue}
89+
formValue={field.value}
9290
onInputChange={form.setValue}
9391
onOptionChange={field.onChange}
9492
parse={{
@@ -125,7 +123,6 @@ describe.skip('EditableDetailV2', () => {
125123
[fieldName]: fieldValue,
126124
},
127125
});
128-
const originalValue = form.watch(fieldName);
129126

130127
return (
131128
<Form {...form}>
@@ -139,7 +136,7 @@ describe.skip('EditableDetailV2', () => {
139136
format={undefined}
140137
isEditable={true}
141138
value={fieldValue}
142-
originalValue={originalValue}
139+
formValue={field.value}
143140
onInputChange={form.setValue}
144141
onOptionChange={field.onChange}
145142
parse={{
@@ -174,7 +171,6 @@ describe.skip('EditableDetailV2', () => {
174171
[fieldName]: fieldValue,
175172
},
176173
});
177-
const originalValue = form.watch(fieldName);
178174

179175
return (
180176
<Form {...form}>
@@ -188,7 +184,7 @@ describe.skip('EditableDetailV2', () => {
188184
format={undefined}
189185
isEditable={true}
190186
value={fieldValue}
191-
originalValue={originalValue}
187+
formValue={field.value}
192188
onInputChange={form.setValue}
193189
onOptionChange={field.onChange}
194190
parse={{
@@ -227,7 +223,6 @@ describe.skip('EditableDetailV2', () => {
227223
[fieldName]: fieldValue,
228224
},
229225
});
230-
const originalValue = form.watch(fieldName);
231226

232227
return (
233228
<Form {...form}>
@@ -241,7 +236,7 @@ describe.skip('EditableDetailV2', () => {
241236
format={undefined}
242237
isEditable={false}
243238
value={fieldValue}
244-
originalValue={originalValue}
239+
formValue={field.value}
245240
onInputChange={form.setValue}
246241
onOptionChange={field.onChange}
247242
parse={{
@@ -278,7 +273,6 @@ describe.skip('EditableDetailV2', () => {
278273
[fieldName]: fieldValue,
279274
},
280275
});
281-
const originalValue = form.watch(fieldName);
282276

283277
return (
284278
<Form {...form}>
@@ -292,7 +286,7 @@ describe.skip('EditableDetailV2', () => {
292286
format={undefined}
293287
isEditable={true}
294288
value={fieldValue}
295-
originalValue={originalValue}
289+
formValue={field.value}
296290
onInputChange={form.setValue}
297291
onOptionChange={field.onChange}
298292
parse={{

apps/backoffice-v2/src/common/components/organisms/EditableDetailsV2/components/EditableDetailV2/EditableDetailV2.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChangeEvent, useCallback } from 'react';
2-
import { ExtendedJson } from '@/common/types';
32
import { checkIsFormattedDatetime } from '@/common/utils/check-is-formatted-datetime';
43
import { FileJson2 } from 'lucide-react';
54
import { BallerineLink, ctw, Input, JsonDialog } from '@ballerine/ui';
@@ -23,7 +22,7 @@ export const EditableDetailV2 = ({
2322
isEditable,
2423
className,
2524
options,
26-
originalValue,
25+
formValue,
2726
onInputChange,
2827
onOptionChange,
2928
name,
@@ -47,7 +46,7 @@ export const EditableDetailV2 = ({
4746
onInputChange: (name: string, value: unknown) => void;
4847
onOptionChange: (...event: any[]) => void;
4948
valueAlias?: string;
50-
originalValue: ExtendedJson;
49+
formValue: any;
5150
type: string | undefined;
5251
format: string | undefined;
5352
minimum?: number;
@@ -62,7 +61,7 @@ export const EditableDetailV2 = ({
6261
nullish?: boolean;
6362
};
6463
}) => {
65-
const displayValue = getDisplayValue({ value, originalValue, isEditable });
64+
const displayValue = getDisplayValue({ value, formValue, isEditable });
6665
const handleInputChange = useCallback(
6766
(event: ChangeEvent<HTMLInputElement>) => {
6867
const getValue = () => {
@@ -113,7 +112,7 @@ export const EditableDetailV2 = ({
113112

114113
if (isEditable && options) {
115114
return (
116-
<Select disabled={!isEditable} onValueChange={onOptionChange} defaultValue={value}>
115+
<Select disabled={!isEditable} onValueChange={onOptionChange} defaultValue={formValue}>
117116
<FormControl>
118117
<SelectTrigger className="h-9 w-full border-input p-1 shadow-sm">
119118
<SelectValue />
@@ -137,7 +136,7 @@ export const EditableDetailV2 = ({
137136
<FormControl>
138137
<Checkbox_
139138
disabled={!isEditable}
140-
checked={value}
139+
checked={isEditable ? formValue : value}
141140
onCheckedChange={onOptionChange}
142141
className={ctw('border-[#E5E7EB]', className)}
143142
/>
@@ -146,7 +145,7 @@ export const EditableDetailV2 = ({
146145
}
147146

148147
if (isEditable) {
149-
const inputType = getInputType({ format, type, value: originalValue });
148+
const inputType = getInputType({ format, type, value });
150149

151150
return (
152151
<FormControl>
@@ -159,9 +158,7 @@ export const EditableDetailV2 = ({
159158
value={displayValue}
160159
onChange={handleInputChange}
161160
autoComplete={'off'}
162-
className={ctw(`p-1`, {
163-
'text-slate-400': isNullish(value) || value === '',
164-
})}
161+
className={`p-1`}
165162
/>
166163
</FormControl>
167164
);

apps/backoffice-v2/src/common/components/organisms/EditableDetailsV2/utils/get-display-value.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import utc from 'dayjs/plugin/utc';
55

66
dayjs.extend(utc);
77

8-
export const getDisplayValue = <TValue, TOriginalValue>({
8+
export const getDisplayValue = <TValue, TFormValue>({
99
value,
10-
originalValue,
10+
formValue,
1111
isEditable,
1212
}: {
1313
value: TValue;
14-
originalValue: TOriginalValue;
14+
formValue: TFormValue;
1515
isEditable: boolean;
1616
}) => {
17-
if (isEditable && checkIsDatetime(value)) {
18-
return dayjs(value).local().format('YYYY-MM-DDTHH:mm:ss');
17+
if (isEditable && checkIsDatetime(formValue)) {
18+
return dayjs(formValue).local().format('YYYY-MM-DDTHH:mm:ss');
1919
}
2020

2121
if (isEditable) {
22-
return originalValue;
22+
return formValue;
2323
}
2424

2525
if (isNullish(value) || value === '') {

0 commit comments

Comments
 (0)