Onboarding JS: refactor function out of repetitive blocks (#5564) [deploy]
This commit is contained in:
parent
4872422373
commit
7436e70158
5 changed files with 21 additions and 46 deletions
|
|
@ -2,7 +2,7 @@ import { h, Component } from 'preact';
|
|||
import PropTypes from 'prop-types';
|
||||
|
||||
import Navigation from './Navigation';
|
||||
import { getContentOfToken } from '../utilities';
|
||||
import { getContentOfToken, updateOnboarding } from '../utilities';
|
||||
|
||||
class BioForm extends Component {
|
||||
constructor(props) {
|
||||
|
|
@ -17,16 +17,7 @@ class BioForm extends Component {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
const csrfToken = getContentOfToken('csrf-token');
|
||||
fetch('/onboarding_update', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'X-CSRF-Token': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ user: { last_onboarding_page: 'bio form' } }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
updateOnboarding('bio form');
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
import { h, Component } from 'preact';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { getContentOfToken } from '../utilities';
|
||||
import { updateOnboarding } from '../utilities';
|
||||
|
||||
class ClosingSlide extends Component {
|
||||
componentDidMount() {
|
||||
const csrfToken = getContentOfToken('csrf-token');
|
||||
fetch('/onboarding_update', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'X-CSRF-Token': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ user: { last_onboarding_page: 'closing slide' } }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
updateOnboarding('closing slide');
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { h, Component } from 'preact';
|
|||
import PropTypes from 'prop-types';
|
||||
|
||||
import Navigation from './Navigation';
|
||||
import { getContentOfToken } from '../utilities';
|
||||
import { getContentOfToken, updateOnboarding } from '../utilities';
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
|
|
@ -27,18 +27,7 @@ class EmailTermsConditionsForm extends Component {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
const csrfToken = getContentOfToken('csrf-token');
|
||||
fetch('/onboarding_update', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'X-CSRF-Token': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user: { last_onboarding_page: 'emails, COC and T&C form' },
|
||||
}),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
updateOnboarding('emails, COC and T&C form');
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|||
|
||||
import Navigation from './Navigation';
|
||||
import SlideContent from './SlideContent';
|
||||
import { getContentOfToken } from '../utilities';
|
||||
import { updateOnboarding } from '../utilities';
|
||||
|
||||
class IntroSlide extends Component {
|
||||
constructor(props) {
|
||||
|
|
@ -13,16 +13,7 @@ class IntroSlide extends Component {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
const csrfToken = getContentOfToken('csrf-token');
|
||||
fetch('/onboarding_update', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'X-CSRF-Token': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ user: { last_onboarding_page: 'intro slide' } }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
updateOnboarding('intro slide');
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
|
|
|
|||
|
|
@ -6,3 +6,16 @@ export const jsonToForm = data => {
|
|||
|
||||
export const getContentOfToken = token =>
|
||||
document.querySelector(`meta[name='${token}']`).content;
|
||||
|
||||
export const updateOnboarding = lastPage => {
|
||||
const csrfToken = getContentOfToken('csrf-token');
|
||||
fetch('/onboarding_update', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'X-CSRF-Token': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ user: { last_onboarding_page: lastPage } }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue