web/satellite: remove duplicated default project creation code
Moved creation of default project to vuex store to dispatch it in different places. It removes duplicated code fragments Change-Id: Ic5e52776727e681797bbd76342b78480812552d1
This commit is contained in:
parent
9e2d837473
commit
c26d52a538
@ -101,25 +101,7 @@ export default class NameStep extends Vue {
|
||||
// Used like backwards compatibility for the old accounts without any project.
|
||||
if (this.$store.getters.projects.length === 0) {
|
||||
try {
|
||||
const FIRST_PAGE = 1;
|
||||
const UNTITLED_PROJECT_NAME = 'My First Project';
|
||||
const UNTITLED_PROJECT_DESCRIPTION = '___';
|
||||
const project = new ProjectFields(
|
||||
UNTITLED_PROJECT_NAME,
|
||||
UNTITLED_PROJECT_DESCRIPTION,
|
||||
this.$store.getters.user.id,
|
||||
);
|
||||
const createdProject = await this.$store.dispatch(PROJECTS_ACTIONS.CREATE, project);
|
||||
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.SELECT, createdProject.id);
|
||||
await this.$store.dispatch(PM_ACTIONS.CLEAR);
|
||||
await this.$store.dispatch(PM_ACTIONS.FETCH, FIRST_PAGE);
|
||||
await this.$store.dispatch(PAYMENTS_ACTIONS.GET_PAYMENTS_HISTORY);
|
||||
await this.$store.dispatch(PAYMENTS_ACTIONS.GET_BALANCE);
|
||||
await this.$store.dispatch(PAYMENTS_ACTIONS.GET_PROJECT_USAGE_AND_CHARGES_CURRENT_ROLLUP);
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.GET_LIMITS, createdProject.id);
|
||||
await this.$store.dispatch(ACCESS_GRANTS_ACTIONS.CLEAR);
|
||||
await this.$store.dispatch(BUCKET_ACTIONS.CLEAR);
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.CREATE_DEFAULT_PROJECT);
|
||||
} catch (error) {
|
||||
await this.$notify.error(error.message);
|
||||
this.isLoading = false;
|
||||
|
@ -145,7 +145,7 @@ export default class OverviewStep extends Vue {
|
||||
await this.analytics.linkEventTriggered(AnalyticsEvent.PATH_SELECTED, 'GatewayMT');
|
||||
|
||||
try {
|
||||
await this.createFirstProject();
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.CREATE_DEFAULT_PROJECT);
|
||||
|
||||
this.isLoading = false;
|
||||
|
||||
@ -168,7 +168,7 @@ export default class OverviewStep extends Vue {
|
||||
await this.analytics.linkEventTriggered(AnalyticsEvent.PATH_SELECTED, 'CLI');
|
||||
|
||||
try {
|
||||
await this.createFirstProject();
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.CREATE_DEFAULT_PROJECT);
|
||||
|
||||
this.isLoading = false;
|
||||
|
||||
@ -190,7 +190,7 @@ export default class OverviewStep extends Vue {
|
||||
await this.analytics.linkEventTriggered(AnalyticsEvent.PATH_SELECTED, 'Continue in Browser');
|
||||
|
||||
try {
|
||||
await this.createFirstProject();
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.CREATE_DEFAULT_PROJECT);
|
||||
|
||||
this.isLoading = false;
|
||||
|
||||
@ -211,7 +211,7 @@ export default class OverviewStep extends Vue {
|
||||
this.isLoading = true;
|
||||
|
||||
try {
|
||||
await this.createFirstProject();
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.CREATE_DEFAULT_PROJECT);
|
||||
|
||||
this.isLoading = false;
|
||||
|
||||
@ -222,32 +222,6 @@ export default class OverviewStep extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates untitled project in a background.
|
||||
*/
|
||||
private async createFirstProject(): Promise<void> {
|
||||
const FIRST_PAGE = 1;
|
||||
const UNTITLED_PROJECT_NAME = 'My First Project';
|
||||
const UNTITLED_PROJECT_DESCRIPTION = '___';
|
||||
const project = new ProjectFields(
|
||||
UNTITLED_PROJECT_NAME,
|
||||
UNTITLED_PROJECT_DESCRIPTION,
|
||||
this.$store.getters.user.id,
|
||||
);
|
||||
const createdProject = await this.$store.dispatch(PROJECTS_ACTIONS.CREATE, project);
|
||||
const createdProjectId = createdProject.id;
|
||||
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.SELECT, createdProjectId);
|
||||
await this.$store.dispatch(PM_ACTIONS.CLEAR);
|
||||
await this.$store.dispatch(PM_ACTIONS.FETCH, FIRST_PAGE);
|
||||
await this.$store.dispatch(PAYMENTS_ACTIONS.GET_PAYMENTS_HISTORY);
|
||||
await this.$store.dispatch(PAYMENTS_ACTIONS.GET_BALANCE);
|
||||
await this.$store.dispatch(PAYMENTS_ACTIONS.GET_PROJECT_USAGE_AND_CHARGES_CURRENT_ROLLUP);
|
||||
await this.$store.dispatch(PROJECTS_ACTIONS.GET_LIMITS, createdProjectId);
|
||||
await this.$store.dispatch(ACCESS_GRANTS_ACTIONS.CLEAR);
|
||||
await this.$store.dispatch(BUCKET_ACTIONS.CLEAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if user has at least one project.
|
||||
*/
|
||||
|
@ -2,6 +2,9 @@
|
||||
// See LICENSE for copying information.
|
||||
|
||||
import { StoreModule } from '@/store';
|
||||
import { ACCESS_GRANTS_ACTIONS } from '@/store/modules/accessGrants';
|
||||
import { BUCKET_ACTIONS } from '@/store/modules/buckets';
|
||||
import { PAYMENTS_ACTIONS } from '@/store/modules/payments';
|
||||
import {
|
||||
Project,
|
||||
ProjectFields,
|
||||
@ -10,11 +13,13 @@ import {
|
||||
ProjectsCursor,
|
||||
ProjectsPage,
|
||||
} from '@/types/projects';
|
||||
import { PM_ACTIONS } from '@/utils/constants/actionNames';
|
||||
|
||||
export const PROJECTS_ACTIONS = {
|
||||
FETCH: 'fetchProjects',
|
||||
FETCH_OWNED: 'fetchOwnedProjects',
|
||||
CREATE: 'createProject',
|
||||
CREATE_DEFAULT_PROJECT: 'createDefaultProject',
|
||||
SELECT: 'selectProject',
|
||||
UPDATE_NAME: 'updateProjectName',
|
||||
UPDATE_DESCRIPTION: 'updateProjectDescription',
|
||||
@ -49,6 +54,7 @@ export class ProjectsState {
|
||||
const {
|
||||
FETCH,
|
||||
CREATE,
|
||||
CREATE_DEFAULT_PROJECT,
|
||||
SELECT,
|
||||
UPDATE_NAME,
|
||||
UPDATE_DESCRIPTION,
|
||||
@ -163,6 +169,27 @@ export function makeProjectsModule(api: ProjectsApi): StoreModule<ProjectsState>
|
||||
|
||||
return project;
|
||||
},
|
||||
[CREATE_DEFAULT_PROJECT]: async function ({rootGetters, dispatch}: any): Promise<void> {
|
||||
const FIRST_PAGE = 1;
|
||||
const UNTITLED_PROJECT_NAME = 'My First Project';
|
||||
const UNTITLED_PROJECT_DESCRIPTION = '___';
|
||||
const project = new ProjectFields(
|
||||
UNTITLED_PROJECT_NAME,
|
||||
UNTITLED_PROJECT_DESCRIPTION,
|
||||
rootGetters.user.id,
|
||||
);
|
||||
const createdProject = await dispatch(PROJECTS_ACTIONS.CREATE, project, {root: true});
|
||||
|
||||
await dispatch(PROJECTS_ACTIONS.SELECT, createdProject.id, {root: true});
|
||||
await dispatch(PM_ACTIONS.CLEAR, null, {root: true});
|
||||
await dispatch(PM_ACTIONS.FETCH, FIRST_PAGE, {root: true});
|
||||
await dispatch(PAYMENTS_ACTIONS.GET_PAYMENTS_HISTORY, null, {root: true});
|
||||
await dispatch(PAYMENTS_ACTIONS.GET_BALANCE, null, {root: true});
|
||||
await dispatch(PAYMENTS_ACTIONS.GET_PROJECT_USAGE_AND_CHARGES_CURRENT_ROLLUP, null, {root: true});
|
||||
await dispatch(PROJECTS_ACTIONS.GET_LIMITS, createdProject.id, {root: true});
|
||||
await dispatch(ACCESS_GRANTS_ACTIONS.CLEAR, null, {root: true});
|
||||
await dispatch(BUCKET_ACTIONS.CLEAR, null, {root: true});
|
||||
},
|
||||
[SELECT]: function ({commit}: any, projectID: string): void {
|
||||
commit(SELECT_PROJECT, projectID);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user