Skip to content

Commit 5d850b3

Browse files
fix: All currency selections are in sync (same)
1 parent 3222524 commit 5d850b3

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/components/JAF/CurrencySelect.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ interface CurrencyOption {
77
symbol: string;
88
}
99

10-
// Default currencies list
1110
const defaultCurrencies: CurrencyOption[] = [
1211
{ value: "INR", label: "INR", symbol: "₹" },
1312
{ value: "USD", label: "USD", symbol: "$" },
@@ -35,9 +34,10 @@ interface CurrencySelectProps {
3534
allowCustom?: boolean;
3635
maxSymbolLength?: number;
3736
maxNameLength?: number;
38-
// Add props for shared custom currencies
3937
customCurrencies: CurrencyOption[];
4038
onAddCustomCurrency: (currency: CurrencyOption) => void;
39+
syncedCurrency?: string;
40+
onCurrencySync?: (currency: string) => void;
4141
}
4242

4343
const CurrencySelect: FC<CurrencySelectProps> = (props) => {
@@ -52,7 +52,6 @@ const CurrencySelect: FC<CurrencySelectProps> = (props) => {
5252
maxSymbolLength = 3,
5353
maxNameLength = 20,
5454
} = props;
55-
// Combine default and custom currencies
5655
const allCurrencies = [...defaultCurrencies, ...props.customCurrencies];
5756
const currentSalary = field && values?.salaries?.[field.name];
5857

@@ -81,14 +80,12 @@ const CurrencySelect: FC<CurrencySelectProps> = (props) => {
8180
)
8281
return;
8382

84-
// Create new currency object
8583
const newCurrency: CurrencyOption = {
8684
value: currentSalary.customCurrencySymbol,
8785
label: currentSalary.customCurrencyName || "Custom",
8886
symbol: currentSalary.customCurrencySymbol,
8987
};
9088

91-
// Check if currency already exists
9289
const exists = allCurrencies.some(
9390
(c) => c.value === newCurrency.value || c.symbol === newCurrency.symbol,
9491
);
@@ -98,10 +95,8 @@ const CurrencySelect: FC<CurrencySelectProps> = (props) => {
9895
return;
9996
}
10097

101-
// Add custom currency through the parent callback
10298
props.onAddCustomCurrency(newCurrency);
10399

104-
// Update the form value
105100
const updatedSalaries = {
106101
...values.salaries,
107102
[field.name]: {
@@ -208,10 +203,22 @@ const CurrencySelect: FC<CurrencySelectProps> = (props) => {
208203
);
209204
};
210205

206+
const handleChange = (value: string) => {
207+
if (props.onCurrencySync) {
208+
props.onCurrencySync(value);
209+
}
210+
};
211+
211212
return (
212-
<Form.Item name={name} noStyle initialValue={defaultValue}>
213+
<Form.Item
214+
name={name}
215+
noStyle
216+
initialValue={props.syncedCurrency || defaultValue}
217+
>
213218
<Select
214219
style={style}
220+
value={props.syncedCurrency}
221+
onChange={handleChange}
215222
dropdownRender={(menu) =>
216223
allowCustom ? (
217224
<>

src/components/JAF/JobDetails.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const JobDetails = ({
6969
setFieldValue,
7070
}: StepProps) => {
7171
const [form] = Form.useForm();
72+
const [syncedCurrency, setSyncedCurrency] = useState("INR");
7273

7374
const [skills, setSkills] = useState([]);
7475
const [fileList, setFileList] = useState([]);
@@ -124,6 +125,19 @@ const JobDetails = ({
124125
);
125126
};
126127

128+
const handleCurrencySync = (currency: string) => {
129+
setSyncedCurrency(currency);
130+
const currentSalaries = form.getFieldValue("salaries");
131+
const updatedSalaries = currentSalaries.map((salary: any) => ({
132+
...salary,
133+
stipendCurrency: currency,
134+
accommodationCurrency: currency,
135+
tentativeCTCCurrency: currency,
136+
foreignStipendCurrency: currency,
137+
}));
138+
form.setFieldValue("salaries", updatedSalaries);
139+
};
140+
127141
useEffect(() => {
128142
axios.get(`${baseUrl}/api/v1/jaf`).then((res) => {
129143
res.data.testTypes.map((it: any) => {
@@ -1174,6 +1188,8 @@ const JobDetails = ({
11741188
allowCustom={true}
11751189
customCurrencies={customCurrencies}
11761190
onAddCustomCurrency={handleAddCustomCurrency}
1191+
syncedCurrency={syncedCurrency}
1192+
onCurrencySync={handleCurrencySync}
11771193
/>
11781194
}
11791195
/>
@@ -1194,14 +1210,16 @@ const JobDetails = ({
11941210
`${field.name}`,
11951211
"foreignStipendCurrency",
11961212
]}
1197-
defaultValue="USD"
1213+
defaultValue="INR"
11981214
style={{ width: 120 }}
11991215
values={values}
12001216
setFieldValue={setFieldValue}
12011217
field={field}
12021218
allowCustom={true}
12031219
customCurrencies={customCurrencies}
12041220
onAddCustomCurrency={handleAddCustomCurrency}
1221+
syncedCurrency={syncedCurrency}
1222+
onCurrencySync={handleCurrencySync}
12051223
/>
12061224
}
12071225
/>
@@ -1232,6 +1250,8 @@ const JobDetails = ({
12321250
allowCustom={true}
12331251
customCurrencies={customCurrencies}
12341252
onAddCustomCurrency={handleAddCustomCurrency}
1253+
syncedCurrency={syncedCurrency}
1254+
onCurrencySync={handleCurrencySync}
12351255
/>
12361256
}
12371257
/>
@@ -1257,6 +1277,8 @@ const JobDetails = ({
12571277
allowCustom={true}
12581278
customCurrencies={customCurrencies}
12591279
onAddCustomCurrency={handleAddCustomCurrency}
1280+
syncedCurrency={syncedCurrency}
1281+
onCurrencySync={handleCurrencySync}
12601282
/>
12611283
}
12621284
/>
@@ -1267,7 +1289,10 @@ const JobDetails = ({
12671289
label="PPO Confirmation Date"
12681290
name={[field.name, "PPOConfirmationDate"]}
12691291
>
1270-
<Input type="date" />
1292+
<Input
1293+
type="date"
1294+
min={new Date().toISOString().split("T")[0]}
1295+
/>
12711296
</Form.Item>
12721297
</>
12731298
)}

0 commit comments

Comments
 (0)