mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
fix: one-click demo account
This commit is contained in:
@@ -3,9 +3,10 @@ import { faker } from '@faker-js/faker';
|
|||||||
import uniqid from 'uniqid';
|
import uniqid from 'uniqid';
|
||||||
import AuthenticationApplication from '../Authentication/AuthApplication';
|
import AuthenticationApplication from '../Authentication/AuthApplication';
|
||||||
import OrganizationService from '../Organization/OrganizationService';
|
import OrganizationService from '../Organization/OrganizationService';
|
||||||
import { IAuthSignInPOJO } from '@/interfaces';
|
|
||||||
import { OneClickDemo } from '@/system/models/OneclickDemo';
|
import { OneClickDemo } from '@/system/models/OneclickDemo';
|
||||||
import { SystemUser } from '@/system/models';
|
import { SystemUser } from '@/system/models';
|
||||||
|
import { IAuthSignInPOJO } from '@/interfaces';
|
||||||
|
import { ICreateOneClickDemoPOJO } from './interfaces';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class CreateOneClickDemo {
|
export class CreateOneClickDemo {
|
||||||
@@ -53,8 +54,9 @@ export class CreateOneClickDemo {
|
|||||||
/**
|
/**
|
||||||
* Sign-in automicatlly using the demo id one creating an account finish.
|
* Sign-in automicatlly using the demo id one creating an account finish.
|
||||||
* @param {string} oneClickDemoId -
|
* @param {string} oneClickDemoId -
|
||||||
|
* @returns {Promise<IAuthSignInPOJO>}
|
||||||
*/
|
*/
|
||||||
async autoSignIn(oneClickDemoId: string) {
|
async autoSignIn(oneClickDemoId: string): Promise<IAuthSignInPOJO> {
|
||||||
const foundOneclickDemo = await OneClickDemo.query()
|
const foundOneclickDemo = await OneClickDemo.query()
|
||||||
.findOne('key', oneClickDemoId)
|
.findOne('key', oneClickDemoId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
@@ -70,10 +72,3 @@ export class CreateOneClickDemo {
|
|||||||
return signedIn;
|
return signedIn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICreateOneClickDemoPOJO {
|
|
||||||
email: string;
|
|
||||||
demoId: string;
|
|
||||||
signedIn: IAuthSignInPOJO;
|
|
||||||
buildJob: any;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,19 +7,19 @@ export class OneClickDemoApplication {
|
|||||||
private createOneClickDemoService: CreateOneClickDemo;
|
private createOneClickDemoService: CreateOneClickDemo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Creates one-click demo account.
|
||||||
* @returns
|
* @returns {Promise<ICreateOneClickDemoPOJO>}
|
||||||
*/
|
*/
|
||||||
public createOneClick() {
|
public createOneClick() {
|
||||||
return this.createOneClickDemoService.createOneClickDemo();
|
return this.createOneClickDemoService.createOneClickDemo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Auto-sign-in to created demo account.
|
||||||
* @param oneClickDemoId
|
* @param {string} demoId -
|
||||||
* @returns
|
* @returns {Promise<IAuthSignInPOJO>}
|
||||||
*/
|
*/
|
||||||
public autoSignIn(oneClickDemoId: string) {
|
public autoSignIn(demoId: string) {
|
||||||
return this.createOneClickDemoService.autoSignIn(oneClickDemoId);
|
return this.createOneClickDemoService.autoSignIn(demoId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
packages/server/src/services/OneClickDemo/interfaces.ts
Normal file
8
packages/server/src/services/OneClickDemo/interfaces.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { IAuthSignInPOJO } from '@/interfaces';
|
||||||
|
|
||||||
|
export interface ICreateOneClickDemoPOJO {
|
||||||
|
email: string;
|
||||||
|
demoId: string;
|
||||||
|
signedIn: IAuthSignInPOJO;
|
||||||
|
buildJob: any;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { Button, Intent, ProgressBar, Spinner, Text } from '@blueprintjs/core';
|
import { Button, Intent, ProgressBar, Text } from '@blueprintjs/core';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
useCreateOneClickDemo,
|
useCreateOneClickDemo,
|
||||||
@@ -14,26 +14,21 @@ export default function OneClickDemoPage() {
|
|||||||
mutateAsync: createOneClickDemo,
|
mutateAsync: createOneClickDemo,
|
||||||
isLoading: isCreateOneClickLoading,
|
isLoading: isCreateOneClickLoading,
|
||||||
} = useCreateOneClickDemo();
|
} = useCreateOneClickDemo();
|
||||||
const { mutateAsync: oneClickDemoSignIn } = useOneClickDemoSignin();
|
const {
|
||||||
|
mutateAsync: oneClickDemoSignIn,
|
||||||
|
isLoading: isOneclickDemoSigningIn,
|
||||||
|
} = useOneClickDemoSignin();
|
||||||
const [buildJobId, setBuildJobId] = useState<string>('');
|
const [buildJobId, setBuildJobId] = useState<string>('');
|
||||||
const [demoId, setDemoId] = useState<string>('');
|
|
||||||
|
|
||||||
// Job done state.
|
// Job states.
|
||||||
|
const [demoId, setDemoId] = useState<string>('');
|
||||||
const [isJobDone, setIsJobDone] = useState<boolean>(false);
|
const [isJobDone, setIsJobDone] = useState<boolean>(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { running, queued, failed, completed },
|
data: { running, completed },
|
||||||
isFetching: isJobFetching,
|
|
||||||
} = useJob(buildJobId, {
|
} = useJob(buildJobId, {
|
||||||
refetchInterval: 2000,
|
refetchInterval: 2000,
|
||||||
enabled: !isJobDone && !!buildJobId,
|
enabled: !isJobDone && !!buildJobId,
|
||||||
onSuccess: (res) => {
|
|
||||||
if (res.completed) {
|
|
||||||
oneClickDemoSignIn({ demoId }).then((res) => {
|
|
||||||
debugger;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -42,15 +37,25 @@ export default function OneClickDemoPage() {
|
|||||||
}
|
}
|
||||||
}, [completed, setIsJobDone]);
|
}, [completed, setIsJobDone]);
|
||||||
|
|
||||||
|
// One the job done request sign-in using the demo id.
|
||||||
|
useEffect(() => {
|
||||||
|
if (isJobDone) {
|
||||||
|
oneClickDemoSignIn({ demoId }).then((res) => {
|
||||||
|
debugger;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isJobDone]);
|
||||||
|
|
||||||
const handleCreateAccountBtnClick = () => {
|
const handleCreateAccountBtnClick = () => {
|
||||||
createOneClickDemo({})
|
createOneClickDemo({})
|
||||||
.then((res) => {
|
.then(({ data: { data } }) => {
|
||||||
setBuildJobId(res?.data?.data?.build_job?.job_id);
|
setBuildJobId(data?.build_job?.job_id);
|
||||||
setDemoId(res?.data?.data?.demo_id);
|
setDemoId(data?.demo_id);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
const isLoading = running;
|
const isLoading = running || isOneclickDemoSigningIn;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className={style.root}>
|
<Box className={style.root}>
|
||||||
@@ -61,10 +66,17 @@ export default function OneClickDemoPage() {
|
|||||||
{isLoading && (
|
{isLoading && (
|
||||||
<Stack align={'center'} spacing={15}>
|
<Stack align={'center'} spacing={15}>
|
||||||
<ProgressBar stripes value={null} className={style.progressBar} />
|
<ProgressBar stripes value={null} className={style.progressBar} />
|
||||||
|
{isOneclickDemoSigningIn && (
|
||||||
|
<Text className={style.waitingText}>
|
||||||
|
It's signin-in to your demo account, Just a second!
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{running && (
|
||||||
<Text className={style.waitingText}>
|
<Text className={style.waitingText}>
|
||||||
We're preparing temporary environment for trial, It typically
|
We're preparing temporary environment for trial, It typically
|
||||||
take few seconds. Do not close or refresh the page.
|
take few seconds. Do not close or refresh the page.
|
||||||
</Text>
|
</Text>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -72,7 +84,7 @@ export default function OneClickDemoPage() {
|
|||||||
{!isLoading && (
|
{!isLoading && (
|
||||||
<Button
|
<Button
|
||||||
className={style.oneClickBtn}
|
className={style.oneClickBtn}
|
||||||
intent={Intent.PRIMARY}
|
intent={Intent.NONE}
|
||||||
onClick={handleCreateAccountBtnClick}
|
onClick={handleCreateAccountBtnClick}
|
||||||
loading={isCreateOneClickLoading}
|
loading={isCreateOneClickLoading}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user