Skip to content

Commit 514e47b

Browse files
committed
MP-176 job dates cond
1 parent b09a8c6 commit 514e47b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/apps/profiles/src/member-profile/work-expirence/ModifyWorkExpirenceModal/ModifyWorkExpirenceModal.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable complexity */
12
import { Dispatch, FC, MutableRefObject, SetStateAction, useRef, useState } from 'react'
23
import { bind, trim } from 'lodash'
34
import { toast } from 'react-toastify'
@@ -82,10 +83,15 @@ const ModifyWorkExpirenceModal: FC<ModifyWorkExpirenceModalProps> = (props: Modi
8283

8384
function handleFormValueChange(key: string, event: React.ChangeEvent<HTMLInputElement>): void {
8485
let value: string | boolean | Date | undefined
86+
const oldFormValues = { ...formValues }
8587

8688
switch (key) {
8789
case 'currentlyWorking':
8890
value = event.target.checked
91+
if (value) {
92+
oldFormValues.endDate = undefined
93+
}
94+
8995
break
9096
case 'startDate':
9197
case 'endDate':
@@ -97,7 +103,7 @@ const ModifyWorkExpirenceModal: FC<ModifyWorkExpirenceModalProps> = (props: Modi
97103
}
98104

99105
setFormValues({
100-
...formValues,
106+
...oldFormValues,
101107
[key]: value,
102108
})
103109
}
@@ -137,6 +143,22 @@ const ModifyWorkExpirenceModal: FC<ModifyWorkExpirenceModalProps> = (props: Modi
137143
return
138144
}
139145

146+
if (formValues.endDate || formValues.startDate) {
147+
if (formValues.endDate && !formValues.startDate && !formValues.currentlyWorking) {
148+
setFormErrors({
149+
startDate: 'Start date is required when end date is given',
150+
})
151+
return
152+
}
153+
154+
if (formValues.startDate && !formValues.endDate && !formValues.currentlyWorking) {
155+
setFormErrors({
156+
endDate: 'End date is required when start date is given',
157+
})
158+
return
159+
}
160+
}
161+
140162
const updatedWorkExpirence: UserTrait = {
141163
cityTown: formValues.city,
142164
company: formValues.company,
@@ -306,7 +328,7 @@ const ModifyWorkExpirenceModal: FC<ModifyWorkExpirenceModalProps> = (props: Modi
306328
label='End Date'
307329
date={formValues.endDate as Date}
308330
onChange={bind(handleFormValueChange, this, 'endDate')}
309-
disabled={false}
331+
disabled={formValues.currentlyWorking as boolean}
310332
error={formErrors.endDate}
311333
dirty
312334
maxDate={new Date()}

src/libs/ui/lib/components/form/form-groups/form-input/input-date-picker/InputDatePicker.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
border: none;
6060
pointer-events: none;
6161
height: 22px;
62+
background: transparent;
6263

6364
&:focus {
6465
outline: none;

0 commit comments

Comments
 (0)