docbrown/app/javascript/onboarding/utilities.js
Vaidehi Joshi dbbeaf2422
Onboarding intro slide tweaks (#7162) [deploy]
* Render the user's name on intro slide of onboarding

* Refactor terms + conditions form in onboarding view

* Style the back button using crayons design system.
* Remove redundant scroll styles (only need `overflow-y: scroll` here).
* Ensure that content is readable, and back button doesn't conflict with content.
* Ensure size of content is same size as "intro slide".
* Remove unnecesary inline styles, use CSS class instead.

* Fix missing userData issue

* Onboarding test cleanup, inline greeting instead of in a variable
2020-04-09 08:57:50 -07:00

32 lines
882 B
JavaScript

export const jsonToForm = (data) => {
const form = new FormData();
data.forEach((item) => form.append(item.key, item.value));
return form;
};
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',
});
};
/**
* A util function to fetch the user's data from off of the document's body.
*
*
* @returns {Object} A JSON object with the parsed user data.
*/
export const userData = () => {
const { user = null } = document.body.dataset;
return JSON.parse(user);
};