Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] setupWizard calling multiple getSetupWizardParameters #15060

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions app/setup-wizard/client/setupWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { callbacks } from '../../callbacks';
import { hasRole } from '../../authorization';
import { Users } from '../../models';
import { t, handleError } from '../../utils';
import { call } from '../../ui-utils';

const cannotSetup = () => {
const showSetupWizard = settings.get('Show_Setup_Wizard');
Expand Down Expand Up @@ -100,26 +101,34 @@ const persistSettings = (state, callback) => {
});
};

Template.setupWizard.onCreated(function() {
this.state = new ReactiveDict();
this.state.set('currentStep', 1);
this.state.set('registerServer', true);
this.state.set('optIn', true);
Template.setupWizard.onCreated(async function() {
const statusDefault = {
currentStep: 1,
registerServer: true,
optIn: true,
};
this.state = new ReactiveDict(statusDefault);

this.wizardSettings = new ReactiveVar([]);
this.allowStandaloneServer = new ReactiveVar(false);

if (localStorage.getItem('wizardFinal')) {
FlowRouter.go('setup-wizard-final');
return;
return FlowRouter.go('setup-wizard-final');
}

const jsonString = localStorage.getItem('wizard');
const state = (jsonString && JSON.parse(jsonString)) || {};
Object.entries(state).forEach((entry) => this.state.set(...entry));
const state = (jsonString && JSON.parse(jsonString)) || statusDefault;
this.state.set(state);

this.autorun(() => {
const state = this.state.all();
state['registration-pass'] = '';
localStorage.setItem('wizard', JSON.stringify(state));
});

this.autorun((c) => {
this.autorun(async (c) => {
const cantSetup = cannotSetup();

if (typeof cantSetup === 'undefined') {
return;
}
Expand All @@ -130,29 +139,20 @@ Template.setupWizard.onCreated(function() {
return;
}

const state = this.state.all();
state['registration-pass'] = '';
localStorage.setItem('wizard', JSON.stringify(state));

if (Meteor.userId()) {
Meteor.call('getSetupWizardParameters', (error, { settings, allowStandaloneServer } = {}) => {
if (error) {
return handleError(error);
}

this.wizardSettings.set(settings);
this.allowStandaloneServer.set(allowStandaloneServer);
});
if (!Meteor.userId()) {
return this.state.set('currentStep', 1);
}

if (this.state.get('currentStep') === 1) {
this.state.set('currentStep', 2);
} else {
this.state.set('registration-pass', '');
}
} else if (this.state.get('currentStep') !== 1) {
this.state.set('currentStep', 1);
if (this.state.get('currentStep') === 1) {
this.state.set('currentStep', 2);
} else {
this.state.set('registration-pass', '');
}
});

const { settings, allowStandaloneServer } = await call('getSetupWizardParameters') || {};
this.wizardSettings.set(settings);
this.allowStandaloneServer.set(allowStandaloneServer);
});

Template.setupWizard.onRendered(function() {
Expand Down