Skip to content

Commit

Permalink
Merge pull request #211 from plausible/onboarding_error
Browse files Browse the repository at this point in the history
Fixed: "View Stats" couldn't be enabled in onboarding wizard, on new installs.
  • Loading branch information
Dan0sz authored May 22, 2024
2 parents 616b6aa + 4a07319 commit c0fe0fe
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.github
/.storybook

/bin
/tests
/node_modules
/assets/src
Expand All @@ -18,11 +19,14 @@
.travis.yml
.editorconfig
.babelrc
.gitpod.yml
.jscrsrc
.jshintrc
.eslintignore
.eslintrc
.eslintrc.json
.nvmrc
.phpcs.xml.dist
.prettierrc.json
.prettierignore
.stylelintrc.json
Expand All @@ -34,12 +38,16 @@
sample-data/wordpress.sql
sample-data/sample-data.numbers
bower.json
codecov.yml
composer.json
composer.lock
npm-shrinkwrap.json
openapitools.json
package.json
package-lock.json
phpunit.xml
phpunit.xml.dist
phpunit-with-integration.xml
plausible-analytics.zip
CHANGELOG.md
README.md
Expand All @@ -52,4 +60,5 @@ contributing.md
postcss.config.js
webpack.config.js
docker-compose.yml
tailwind.config.js
wp-textdomain.js
44 changes: 30 additions & 14 deletions assets/src/js/admin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,34 @@ document.addEventListener('DOMContentLoaded', () => {
saveOptionOnNext: function (e) {
let hash = document.location.hash.replace('#', '');

if (hash === 'api_token_slide' || hash === 'domain_name_slide') {
let form = e.target.closest('.plausible-analytics-wizard-step-section');
let inputs = form.getElementsByTagName('INPUT');
let options = [];

for (let input of inputs) {
options.push({name: input.name, value: input.value});
}
if (hash !== 'api_token_slide' && hash !== 'domain_name_slide') {
return;
}

let data = new FormData();
data.append('action', 'plausible_analytics_save_options');
data.append('options', JSON.stringify(options));
data.append('_nonce', plausible.nonce);
let form = e.target.closest('.plausible-analytics-wizard-step-section');
let inputs = form.getElementsByTagName('INPUT');
let options = [];

plausible.ajax(data);
for (let input of inputs) {
options.push({name: input.name, value: input.value});
}

let data = new FormData();

data.append('action', 'plausible_analytics_save_options');
data.append('options', JSON.stringify(options));
data.append('_nonce', plausible.nonce);

plausible.ajax(data).then(response => {
/**
* Disable View Stats button, if API token is entered and valid.
*/
if (hash === 'api_token_slide' && response.success === true) {
let stats_button = document.getElementById('enable_analytics_dashboard_view_stats_in_wordpress');

stats_button.removeAttribute('disabled');
}
});
},

/**
Expand Down Expand Up @@ -358,7 +370,11 @@ document.addEventListener('DOMContentLoaded', () => {

document.dispatchEvent(event);

return response.data;
if (response.data !== undefined) {
return response.data;
} else {
return response;
}
});
},

Expand Down
Loading

0 comments on commit c0fe0fe

Please sign in to comment.