-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from bigcapitalhq/fix-webapp-env-variables
fix: Make webapp package env variables dynamic
- Loading branch information
Showing
12 changed files
with
186 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/webapp/src/containers/OneClickDemo/OneClickDemoBoot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { createContext, useContext, ReactNode } from 'react'; | ||
import { useAuthMetadata } from '@/hooks/query/authentication'; | ||
|
||
interface OneClickDemoContextType { | ||
authMeta: any; | ||
} | ||
|
||
const OneClickDemoContext = createContext<OneClickDemoContextType>( | ||
{} as OneClickDemoContextType, | ||
); | ||
|
||
export const useOneClickDemoBoot = () => { | ||
const context = useContext(OneClickDemoContext); | ||
|
||
if (!context) { | ||
throw new Error( | ||
'useOneClickDemo must be used within a OneClickDemoProvider', | ||
); | ||
} | ||
return context; | ||
}; | ||
|
||
interface OneClickDemoBootProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const OneClickDemoBoot: React.FC<OneClickDemoBootProps> = ({ | ||
children, | ||
}) => { | ||
const { isLoading: isAuthMetaLoading, data: authMeta } = useAuthMetadata(); | ||
|
||
const value = { | ||
isAuthMetaLoading, | ||
authMeta, | ||
}; | ||
|
||
if (isAuthMetaLoading) { | ||
return null; | ||
} | ||
return ( | ||
<OneClickDemoContext.Provider value={value}> | ||
{children} | ||
</OneClickDemoContext.Provider> | ||
); | ||
}; |
103 changes: 11 additions & 92 deletions
103
packages/webapp/src/containers/OneClickDemo/OneClickDemoPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,16 @@ | ||
// @ts-nocheck | ||
import { Button, Intent, ProgressBar, Text } from '@blueprintjs/core'; | ||
import { useEffect, useState } from 'react'; | ||
import { | ||
useCreateOneClickDemo, | ||
useOneClickDemoSignin, | ||
} from '@/hooks/query/oneclick-demo'; | ||
import { Box, Icon, Stack } from '@/components'; | ||
import { useJob } from '@/hooks/query'; | ||
import style from './OneClickDemoPage.module.scss'; | ||
import { EnsureAuthNotAuthenticated } from '@/components/Guards/EnsureAuthNotAuthenticated'; | ||
import { EnsureOneClickDemoAccountEnabled } from './EnsureOneClickDemoAccountEnabled'; | ||
import { OneClickDemoBoot } from './OneClickDemoBoot'; | ||
import { OneClickDemoPageContent } from './OneClickDemoPageContent'; | ||
|
||
export default function OneClickDemoPage() { | ||
const { | ||
mutateAsync: createOneClickDemo, | ||
isLoading: isCreateOneClickLoading, | ||
} = useCreateOneClickDemo(); | ||
const { | ||
mutateAsync: oneClickDemoSignIn, | ||
isLoading: isOneclickDemoSigningIn, | ||
} = useOneClickDemoSignin(); | ||
|
||
// Job states. | ||
const [demoId, setDemoId] = useState<string>(''); | ||
const [buildJobId, setBuildJobId] = useState<string>(''); | ||
const [isJobDone, setIsJobDone] = useState<boolean>(false); | ||
|
||
const { | ||
data: { running, completed }, | ||
} = useJob(buildJobId, { | ||
refetchInterval: 2000, | ||
enabled: !isJobDone && !!buildJobId, | ||
}); | ||
|
||
useEffect(() => { | ||
if (completed) { | ||
setIsJobDone(true); | ||
} | ||
}, [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 = () => { | ||
createOneClickDemo({}) | ||
.then(({ data: { data } }) => { | ||
setBuildJobId(data?.build_job?.job_id); | ||
setDemoId(data?.demo_id); | ||
}) | ||
.catch(() => {}); | ||
}; | ||
const isLoading = running || isOneclickDemoSigningIn; | ||
|
||
return ( | ||
<Box className={style.root}> | ||
<Box className={style.inner}> | ||
<Stack align={'center'} spacing={40}> | ||
<Icon icon="bigcapital" height={37} width={228} /> | ||
|
||
{isLoading && ( | ||
<Stack align={'center'} spacing={15}> | ||
<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}> | ||
We're preparing temporary environment for trial, It typically | ||
take few seconds. Do not close or refresh the page. | ||
</Text> | ||
)} | ||
</Stack> | ||
)} | ||
</Stack> | ||
|
||
{!isLoading && ( | ||
<Button | ||
className={style.oneClickBtn} | ||
intent={Intent.NONE} | ||
onClick={handleCreateAccountBtnClick} | ||
loading={isCreateOneClickLoading} | ||
> | ||
Create Demo Account | ||
</Button> | ||
)} | ||
</Box> | ||
</Box> | ||
<EnsureAuthNotAuthenticated> | ||
<OneClickDemoBoot> | ||
<EnsureOneClickDemoAccountEnabled> | ||
<OneClickDemoPageContent /> | ||
</EnsureOneClickDemoAccountEnabled> | ||
</OneClickDemoBoot> | ||
</EnsureAuthNotAuthenticated> | ||
); | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/webapp/src/containers/OneClickDemo/OneClickDemoPageContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// @ts-nocheck | ||
import { Button, Intent, ProgressBar, Text } from '@blueprintjs/core'; | ||
import { useEffect, useState } from 'react'; | ||
import { | ||
useCreateOneClickDemo, | ||
useOneClickDemoSignin, | ||
} from '@/hooks/query/oneclick-demo'; | ||
import { Box, Icon, Stack } from '@/components'; | ||
import { useJob } from '@/hooks/query'; | ||
import style from './OneClickDemoPage.module.scss'; | ||
|
||
export function OneClickDemoPageContent() { | ||
const { | ||
mutateAsync: createOneClickDemo, | ||
isLoading: isCreateOneClickLoading, | ||
} = useCreateOneClickDemo(); | ||
const { | ||
mutateAsync: oneClickDemoSignIn, | ||
isLoading: isOneclickDemoSigningIn, | ||
} = useOneClickDemoSignin(); | ||
|
||
// Job states. | ||
const [demoId, setDemoId] = useState<string>(''); | ||
const [buildJobId, setBuildJobId] = useState<string>(''); | ||
const [isJobDone, setIsJobDone] = useState<boolean>(false); | ||
|
||
const { | ||
data: { running, completed }, | ||
} = useJob(buildJobId, { | ||
refetchInterval: 2000, | ||
enabled: !isJobDone && !!buildJobId, | ||
}); | ||
|
||
useEffect(() => { | ||
if (completed) { | ||
setIsJobDone(true); | ||
} | ||
}, [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 = () => { | ||
createOneClickDemo({}) | ||
.then(({ data: { data } }) => { | ||
setBuildJobId(data?.build_job?.job_id); | ||
setDemoId(data?.demo_id); | ||
}) | ||
.catch(() => {}); | ||
}; | ||
const isLoading = running || isOneclickDemoSigningIn; | ||
|
||
return ( | ||
<Box className={style.root}> | ||
<Box className={style.inner}> | ||
<Stack align={'center'} spacing={40}> | ||
<Icon icon="bigcapital" height={37} width={228} /> | ||
|
||
{isLoading && ( | ||
<Stack align={'center'} spacing={15}> | ||
<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}> | ||
We're preparing temporary environment for trial, It typically | ||
take few seconds. Do not close or refresh the page. | ||
</Text> | ||
)} | ||
</Stack> | ||
)} | ||
</Stack> | ||
|
||
{!isLoading && ( | ||
<Button | ||
className={style.oneClickBtn} | ||
intent={Intent.NONE} | ||
onClick={handleCreateAccountBtnClick} | ||
loading={isCreateOneClickLoading} | ||
> | ||
Create Demo Account | ||
</Button> | ||
)} | ||
</Box> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.