Unverified Commit 4a1c5f17 authored by Zhou (Link)  Fang's avatar Zhou (Link) Fang Committed by GitHub
Browse files

Fixed can't skip a wg issue (#297)

* Fixed can't skip a wg issue

* Added a missing property back for updating formvalues
parent 2a8d4fe0
......@@ -80,6 +80,7 @@ export default function Application() {
purchasingAndVAT,
membershipLevel,
'membershipLevel-label': membershipLevelLabel,
workingGroups: formikWorkingGroups.values.workingGroups,
signingAuthorityRepresentative: signingAuthorityRepresentative,
};
setUpdatedFormValues(theNewValue);
......@@ -159,7 +160,7 @@ export default function Application() {
setUpdatedFormValues({ ...updatedFormValues, workingGroups });
console.log('updated working groups: ', values);
if (values.isJoiningWG) {
if (!values.skipJoiningWG) {
// If the user is joining at least 1 wg, then make related API call
const setFieldValueObj = {
fieldName: 'workingGroups',
......
......@@ -67,7 +67,7 @@ const WorkingGroupsWrapper = ({ formik, formikOrgValue, fullWorkingGroupList, wo
const handleClearData = () => {
// if user check it, we need to delete all wgs in formik and db
formik.values.workingGroups.map((item) => {
deleteData(currentFormId, END_POINT.working_groups, item.id, console.log, `Deleted ${item.workingGroup.label}`);
deleteData(currentFormId, END_POINT.working_groups, item.id, console.log, `Deleted ${item?.workingGroup?.label}`);
return null;
});
formik.setFieldValue('skipJoiningWG', true);
......
......@@ -89,22 +89,25 @@ export const validationSchema = [
// Third step - working groups
yup.object().shape({
workingGroups: yup.array().of(
yup.object().shape({
workingGroup: yup
.object()
.nullable()
.required('Please enter/select a valid working group')
.test('workingGroup', 'Please enter/select a valid working group', function (selectedWG) {
const allWorkingGroups = this.options.parent?.allWorkingGroups;
const typedWG = this.options.parent?.['workingGroup-label'];
const isValid = allWorkingGroups?.includes(typedWG) && selectedWG?.label ? true : false;
return typedWG ? isValid : true;
}),
participationLevel: REQUIRED_MAX_YUP,
workingGroupRepresentative: CONTACT_YUP,
})
),
workingGroups: yup.array().when('skipJoiningWG', {
is: false,
then: yup.array().of(
yup.object().shape({
workingGroup: yup
.object()
.nullable()
.required('Please enter/select a valid working group')
.test('workingGroup', 'Please enter/select a valid working group', function (selectedWG) {
const allWorkingGroups = this.options.parent?.allWorkingGroups;
const typedWG = this.options.parent?.['workingGroup-label'];
const isValid = allWorkingGroups?.includes(typedWG) && selectedWG?.label ? true : false;
return typedWG ? isValid : true;
}),
participationLevel: REQUIRED_MAX_YUP,
workingGroupRepresentative: CONTACT_YUP,
})
),
}),
}),
// Forth, signing Authority
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment