docbrown/app/javascript/onboarding/utilities.js
Mac Siri 4b37f2384c
Refactor OnboardingsController (#17329)
* Refactor OnboardingsController

* Fix broken spec

* Update policy

* Fix spec

* Update config/routes.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Touchup

* Update routes

* Screw it, let's move notification_settings too

* Revert "Screw it, let's move notification_settings too"

This reverts commit aead8c05f4dda62cbc46cdd033afd0acdef2ad73.

* Temp .travis.yml changes

* Revert "Temp .travis.yml changes"

This reverts commit c26109843ba027f9a524e66282a9b01f0341f836.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-04-27 16:17:02 -04:00

32 lines
875 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', {
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);
};