Skip to content

Commit

Permalink
fixed survey proprietor issue (#353)
Browse files Browse the repository at this point in the history
* fixed surve proprietor issue:

* clean up

* format
  • Loading branch information
anissa-agahchen authored Jun 10, 2021
1 parent a9f1e5d commit bf57c67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions api/src/paths/project/{projectId}/survey/{surveyId}/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,22 @@ export const updateSurveyProprietorData = async (
if (!wasProprietary && !isProprietary) {
// 1. did not have proprietor data; still not requiring proprietor data
// do nothing

return;
} else if (wasProprietary && !isProprietary) {
// 2. did have proprietor data; no longer requires proprietor data
// delete old record

sqlStatement = deleteSurveyProprietorSQL(surveyId, putProprietorData.id);
} else if (!wasProprietary && isProprietary) {
// 3. did not have proprietor data; now requires proprietor data
// insert new record

sqlStatement = postSurveyProprietorSQL(surveyId, new PostSurveyProprietorData(entities.survey_proprietor));
} else {
// 4. did have proprietor data; updating proprietor data
// update existing record

sqlStatement = putSurveyProprietorSQL(surveyId, putProprietorData);
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/features/surveys/components/ProprietaryDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export const ProprietaryDataInitialValues: IProprietaryDataForm = {
export const ProprietaryDataYupSchema = yup.object().shape({
proprietary_data_category: yup
.number()
.when('survey_data_proprietary', { is: 'true', then: yup.number().required('Required') }),
.when('survey_data_proprietary', { is: 'true', then: yup.number().min(1, 'required').required('Required') }),
proprietor_name: yup
.string()
.when('survey_data_proprietary', { is: 'true', then: yup.string().required('Required') }),
first_nations_id: yup.number().when('survey_data_category', { is: 2, then: yup.number().min(1, 'required') }),
category_rationale: yup
.string()
.max(3000, 'Cannot exceed 3000 characters')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const SurveyProprietaryData: React.FC<ISurveyProprietaryDataProps> = (props) =>
} = props;

const [openEditDialog, setOpenEditDialog] = useState(false);
const [surveyDataForUpdate, setSurveyDataForUpdate] = useState<IGetSurveyForUpdateResponseProprietor | null>(null);
const [
surveyProprietorDataForUpdate,
setSurveyDataForUpdate
] = useState<IGetSurveyForUpdateResponseProprietor | null>(null);
const [surveyProprietorFormData, setSurveyProprietorFormData] = useState<IProprietaryDataForm>(
ProprietaryDataInitialValues
);
Expand All @@ -69,6 +72,7 @@ const SurveyProprietaryData: React.FC<ISurveyProprietaryDataProps> = (props) =>

const handleDialogEditOpen = async () => {
if (!survey_proprietor) {
setSurveyDataForUpdate(null);
setSurveyProprietorFormData(ProprietaryDataInitialValues);
setOpenEditDialog(true);
return;
Expand Down Expand Up @@ -117,8 +121,8 @@ const SurveyProprietaryData: React.FC<ISurveyProprietaryDataProps> = (props) =>
const surveyData = {
survey_proprietor: {
...values,
id: surveyDataForUpdate?.id,
revision_count: surveyDataForUpdate?.revision_count
id: surveyProprietorDataForUpdate?.id,
revision_count: surveyProprietorDataForUpdate?.revision_count
}
};

Expand Down

0 comments on commit bf57c67

Please sign in to comment.