Skip to content

Commit 190f97e

Browse files
committed
PM-853 - add cancelled reason
1 parent babaa8e commit 190f97e

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/components/ProjectForm/index.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { get } from 'lodash'
55
import styles from './ProjectForm.module.scss'
66
import { PrimaryButton } from '../Buttons'
77
import Select from '../Select'
8-
import { PROJECT_STATUSES, DEFAULT_NDA_UUID } from '../../config/constants'
8+
import { PROJECT_STATUSES, PROJECT_STATUS, DEFAULT_NDA_UUID } from '../../config/constants'
99
import GroupsFormField from './GroupsFormField'
1010

1111
const ProjectForm = ({
@@ -24,11 +24,13 @@ const ProjectForm = ({
2424
handleSubmit,
2525
control,
2626
reset,
27-
formState: { isDirty, errors }
27+
formState: { isDirty, errors },
28+
watch
2829
} = useForm({
2930
defaultValues: {
3031
projectName: isEdit ? projectDetail.name : '',
3132
description: isEdit ? projectDetail.description : '',
33+
cancelReason: null,
3234
status: isEdit
3335
? PROJECT_STATUSES.find((item) => item.value === projectDetail.status) ||
3436
null
@@ -41,17 +43,22 @@ const ProjectForm = ({
4143
}
4244
})
4345

46+
const projectStatus = watch('status')
47+
const isProjectCancelled = get(projectStatus, 'value') === PROJECT_STATUS.CANCELLED
48+
4449
// Handle form submission
4550
const onSubmit = async (data) => {
4651
// indicate that creating process has started
4752
setIsSaving(true)
4853

4954
try {
55+
const status = canManage ? (data.status || {}).value : undefined
5056
const payload = {
5157
name: data.projectName,
5258
description: data.description,
5359
type: data.projectType.value,
54-
status: canManage ? (data.status || {}).value : undefined,
60+
status,
61+
cancelReason: status === PROJECT_STATUS.CANCELLED ? data.cancelReason : undefined,
5562
groups: data.groups,
5663
terms: data.terms ? [data.terms] : []
5764
}
@@ -142,6 +149,35 @@ const ProjectForm = ({
142149
</div>
143150
</div>
144151
)}
152+
{isEdit && isProjectCancelled && (
153+
<Controller
154+
name='cancelReason'
155+
control={control}
156+
rules={{ required: 'Please provide a cancellation reason' }}
157+
render={({ field }) => (
158+
<div className={cn(styles.row)}>
159+
<div className={cn(styles.formLabel, styles.field)}>
160+
<label label htmlFor='status'>
161+
Cancel reason <span>*</span> :
162+
</label>
163+
</div>
164+
<div className={cn(styles.field, styles.formField)}>
165+
<input
166+
className={styles.projectName}
167+
id='cancelReason'
168+
placeholder='Reason'
169+
{...field}
170+
/>
171+
{errors.projectStatus && (
172+
<div className={cn(styles.error)}>
173+
{errors.projectStatus.message}
174+
</div>
175+
)}
176+
</div>
177+
</div>
178+
)}
179+
/>
180+
)}
145181
{!isEdit && (
146182
<div className={cn(styles.row)}>
147183
<div className={cn(styles.formLabel, styles.field)}>

0 commit comments

Comments
 (0)