Skip to content

Commit

Permalink
feat(profile-form): send post request to ortto
Browse files Browse the repository at this point in the history
  • Loading branch information
wri7tno committed Jan 17, 2025
1 parent 6be89ab commit 4d03ba0
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion components/forms/profile/actions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { createThunkAction } from 'redux/actions';
import axios from 'axios';
import { FORM_ERROR } from 'final-form';

import { updateProfile, createProfile } from 'services/user';
import { setMyGFW } from 'providers/mygfw-provider/actions';

const saveOrttoProfile = async (data) => {
const payload = {
email: data.email,
first_name: data.firstName,
last_name: data.lastName,
organization: data.applicationData.gfw.company,
job_title: data.applicationData.gfw.jobTitle,
job_function: data.applicationData.gfw.subsector,
sector: data.applicationData.gfw.sector,
city: data.applicationData.gfw.city,
country: data.applicationData.gfw.country,
preferred_language: data.applicationData.gfw.preferred_language,
interests: data.applicationData.gfw.interests.toString(),
};

try {
await axios.post('https://ortto.wri.org/custom-forms/gfw/', payload);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
};

export const saveProfile = createThunkAction(
'saveProfile',
(fields) => (dispatch) => {
Expand Down Expand Up @@ -76,8 +100,13 @@ export const saveProfile = createThunkAction(
const updateOrCreate = isUserProfileFilled ? updateProfile : createProfile;

return updateOrCreate(id, postData)
.then((response) => {
.then(async (response) => {
if (response.data && response.data.data) {
// if isUserProfileFilled and receive_updates is true, send POST
if (postData.applicationData.gfw.receive_updates) {
saveOrttoProfile(postData);
}

const { attributes } = response.data.data;
dispatch(
setMyGFW({
Expand Down

0 comments on commit 4d03ba0

Please sign in to comment.