Skip to content

Commit

Permalink
feat: add error handling to contact and organization creation and sea…
Browse files Browse the repository at this point in the history
…rch functionalities
  • Loading branch information
Louifine committed Feb 26, 2025
1 parent bf9046e commit 62826e2
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 78 deletions.
79 changes: 41 additions & 38 deletions recoco/frontend/src/js/components/CreateContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,47 @@ function CreateContact() {
this.modalCreateContact.classList.toggle('d-none');
},
createContact() {
if (this.$store.contact.orgaSelected) {
this.contactOrganization = this.$store.contact.orgaSelected;
this.verifOrga = false;
} else {
this.verifOrga = true;
}
if (this.contactJob.length === 0) {
this.verifPoste = true;
} else {
this.verifPoste = false;
}
if (this.contactEmail.length === 0 || this.contactTel.length === 0) {
this.verifMailOrPhone = true;
} else {
this.verifMailOrPhone = false;
}
if (
this.contactOrganization &&
this.contactJob.length > 0 &&
(this.contactEmail.length > 0 || this.contactTel.length > 0)
) {
this.contact = {
organization: this.contactOrganization.id,
last_name: this.contactLastName,
first_name: this.contactFirstName,
division: this.contactJob,
email: this.contactEmail,
phone_no: this.contactTel,
mobile_no: this.contactPhone,
};
api.post(contactsUrl(), this.contact).then((response) => {
this.contact = response.data;
this.$store.contact.createdContact = this.contact;
console.log('createdContact', this.$store.contact.createdContact);
});
this.resetFormValue();
this.closeCreateContactModal();
try {
if (this.$store.contact.orgaSelected) {
this.contactOrganization = this.$store.contact.orgaSelected;
this.verifOrga = false;
} else {
this.verifOrga = true;
}
if (this.contactJob.length === 0) {
this.verifPoste = true;
} else {
this.verifPoste = false;
}
if (this.contactEmail.length === 0 || this.contactTel.length === 0) {
this.verifMailOrPhone = true;
} else {
this.verifMailOrPhone = false;
}
if (
this.contactOrganization &&
this.contactJob.length > 0 &&
(this.contactEmail.length > 0 || this.contactTel.length > 0)
) {
this.contact = {
organization: this.contactOrganization.id,
last_name: this.contactLastName,
first_name: this.contactFirstName,
division: this.contactJob,
email: this.contactEmail,
phone_no: this.contactTel,
mobile_no: this.contactPhone,
};
api.post(contactsUrl(), this.contact).then((response) => {
this.contact = response.data;
this.$store.contact.createdContact = this.contact;
console.log('createdContact', this.$store.contact.createdContact);
});
this.resetFormValue();
this.closeCreateContactModal();
}
} catch (error) {
console.log(error);
}
},
resetFormValue() {
Expand All @@ -84,7 +88,6 @@ function CreateContact() {
this.$store.contact.orgaSelected = null;
this.$store.contact.orgaCreated = null;
this.$dispatch('reset-orga-name');
// this.$store.contact.createdContact = null;
},
};
}
Expand Down
55 changes: 36 additions & 19 deletions recoco/frontend/src/js/components/CreateOrganisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,36 @@ function CreateOrganisation() {
},
onSearchOrgaGroup() {
this.isAnOrgaSelected = false;
if (this.userInput.length > 0) {
this.organisationGroup = null;
this.showOrgaGroupsresults = true
this.isAnOrgaGroupSelected = false;
this.orgaGroupFound = [];
api.get(searchOrganizationGroupsUrl(this.userInput)).then((response) => {
this.searchResults = response.data;
this.orgaGroupsFound = this.searchResults.results;
if (this.orgaGroupsFound.length > 0) {
this.showOrgaGroupsresults = true;
console.log('orgaGroupsFound', this.orgaGroupsFound);
} else {
this.showOrgaGroupsresults = false;
}
});
try {
if (this.userInput.length > 0) {
this.organisationGroup = null;
this.showOrgaGroupsresults = true
this.isAnOrgaGroupSelected = false;
this.orgaGroupFound = [];
api.get(searchOrganizationGroupsUrl(this.userInput)).then((response) => {
this.searchResults = response.data;
this.orgaGroupsFound = this.searchResults.results;
if (this.orgaGroupsFound.length > 0) {
this.showOrgaGroupsresults = true;
} else {
this.showOrgaGroupsresults = false;
}
});
}
} catch (error) {
console.log(error);
}
},
async showDepartments() {
const response = await api.get(departmentsUrl());
this.departments = response.data;
this.$dispatch('on-department-fetch', this.departments);
try {
const response = await api.get(departmentsUrl());
this.departments = response.data;
this.$dispatch('on-department-fetch', this.departments);
}
catch (error) {
console.log(error);
}

},
onSelectGroup(group) {
this.isAnOrgaGroupSelected = true;
Expand All @@ -71,9 +80,13 @@ function CreateOrganisation() {
};
this.isAnOrgaGroupSelected = true;
this.showOrgaGroupsresults = false;
api.post(organizationGroupsUrl(), this.organisationGroup).then((response) => {
try {
api.post(organizationGroupsUrl(), this.organisationGroup).then((response) => {
this.organisationGroup = response.data;
});
} catch (error) {
console.log(error);
}
},
createOrganisation() {
this.selectedDepartments = [...this.$store.contact.selectedDepartments];
Expand Down Expand Up @@ -112,13 +125,17 @@ function CreateOrganisation() {
departments: this.selectedDepartments,
};
}
try {
api.post(organizationsUrl(), this.organisationToCreate).then((response) => {
this.organisationToCreate = response.data;
this.$store.contact.orgaSelected = this.organisationToCreate;
this.$store.contact.orgaCreated = this.organisationToCreate;
this.resetFormValue();
this.closeCreateOrganisationModal();
});
} catch (error) {
console.log(error);
}
}
},
resetFormValue() {
Expand Down
22 changes: 13 additions & 9 deletions recoco/frontend/src/js/components/SearchContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ function SearchContact() {
this.noSearch = false;
if (this.userInput.length > 0 && !this.isAContactSelected) {
this.contactsFound = [];
api.get(searchContactsUrl(this.userInput)).then((response) => {
this.searchResults = response.data;
this.contactsFound = this.searchResults.results;
if (this.contactsFound.length > 0) {
this.showContactsresults = true;
} else {
this.showContactsresults = false;
}
});
try {
api.get(searchContactsUrl(this.userInput)).then((response) => {
this.searchResults = response.data;
this.contactsFound = this.searchResults.results;
if (this.contactsFound.length > 0) {
this.showContactsresults = true;
} else {
this.showContactsresults = false;
}
});
} catch (error) {
console.log(error);
}
} else if (this.userInput.length === 0) {
this.noSearch = true;
}
Expand Down
28 changes: 16 additions & 12 deletions recoco/frontend/src/js/components/SearchOrganisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ function SearchOrganisation() {
},
onSearch() {
this.isAnOrgaSelected = false;
if (this.userInput.length > 0) {
this.orgaFound = [];
api.get(searchOrganizationsUrl(this.userInput)).then((response) => {
this.searchResults = response.data;
this.orgaFound = this.searchResults.results;
if (this.orgaFound.length > 0) {
this.sortOrgasResults();
this.showOrgasresults = true;
} else {
this.showOrgasresults = false;
}
});
try {
if (this.userInput.length > 0) {
this.orgaFound = [];
api.get(searchOrganizationsUrl(this.userInput)).then((response) => {
this.searchResults = response.data;
this.orgaFound = this.searchResults.results;
if (this.orgaFound.length > 0) {
this.sortOrgasResults();
this.showOrgasresults = true;
} else {
this.showOrgasresults = false;
}
});
}
} catch (error) {
console.log(error);
}
},
onSelectOrga(orga) {
Expand Down

0 comments on commit 62826e2

Please sign in to comment.