diff --git a/components/forms/newsletter/component.jsx b/components/forms/newsletter/component.jsx
index 6820bb5000..ee25b906e2 100644
--- a/components/forms/newsletter/component.jsx
+++ b/components/forms/newsletter/component.jsx
@@ -11,6 +11,7 @@ import Select from 'components/forms/components/select';
import Submit from 'components/forms/components/submit';
import SuccessMessage from 'components/success-message';
import Error from 'components/forms/components/error';
+import { preferredLanguages } from 'components/forms/profile/config';
import { email as validateEmail } from 'components/forms/validations';
import Checkbox from '../components/checkbox/component';
@@ -29,14 +30,6 @@ const sectors = [
'Other',
];
-const preferredLanguages = [
- { label: 'English', value: 'en' },
- { label: 'Français', value: 'fr' },
- { label: 'Español', value: 'es' },
- { label: 'Português', value: 'pt' },
- { label: 'Bahasa Indonesia', value: 'id' },
-];
-
const interests = [
'Innovations in Monitoring',
'Fires',
diff --git a/components/forms/profile/actions.js b/components/forms/profile/actions.js
index 34893a5fb1..41699833e7 100644
--- a/components/forms/profile/actions.js
+++ b/components/forms/profile/actions.js
@@ -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('/api/ortto', payload);
+ } catch (error) {
+ // eslint-disable-next-line no-console
+ console.error(error);
+ }
+};
+
export const saveProfile = createThunkAction(
'saveProfile',
(fields) => (dispatch) => {
@@ -29,6 +53,8 @@ export const saveProfile = createThunkAction(
jobTitle,
signUpForTesting,
isUserProfileFilled,
+ receive_updates = false,
+ preferred_language = 'en',
} = fields;
const postData = {
@@ -47,6 +73,8 @@ export const saveProfile = createThunkAction(
aoiCountry,
jobTitle,
areaOrRegionOfInterest,
+ receive_updates,
+ preferred_language,
subsector:
subsector && subsector.includes('Other')
? `Other: ${subsector_otherInput || ''}`
@@ -72,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({
diff --git a/components/forms/profile/component.jsx b/components/forms/profile/component.jsx
index df45b72073..3b36d36269 100644
--- a/components/forms/profile/component.jsx
+++ b/components/forms/profile/component.jsx
@@ -14,6 +14,7 @@ import Submit from 'components/forms/components/submit';
import ConfirmationMessage from 'components/confirmation-message';
import Button from 'components/ui/button';
import Error from 'components/forms/components/error';
+import { preferredLanguages } from 'components/forms/profile/config';
import {
email as validateEmail,
@@ -155,15 +156,17 @@ class ProfileForm extends PureComponent {
label="What topics are you interested in?"
multiple
required
- options={[
- ...sortBy(
- interests.map((r) => ({
- label: r,
- value: r.replace(/( )+|(\/)+/g, '_'),
- })),
- 'label'
- ),
- ]}
+ options={interests.map((r) => ({
+ label: r,
+ value: r.replace(/( )+|(\/)+/g, '_').toLowerCase(),
+ }))}
+ />
+
+
{
+ if (req.method !== 'POST') {
+ return res.status(405);
+ }
+ const payload = req.body;
+
+ console.log('payload to ortto: ', payload);
+
+ try {
+ await axios.post('https://ortto.wri.org/custom-forms/gfw/', payload);
+ } catch (error) {
+ // eslint-disable-next-line no-console
+ console.error(error);
+ return res.status(400);
+ }
+
+ return res.status(201);
+};