@@ -4,13 +4,16 @@ import { BlackButton } from "../../../components/style/global-style";
44import { registerScene } from "../../../scene-view" ;
55import { PluginSdk } from "@plugin-sdk/app" ;
66import type { IReflectNodeReference } from "@design-sdk/core/nodes/lignt" ;
7+ import { isAuthenticated } from "../../../auth" ;
8+ import { useHistory } from "react-router-dom" ;
79
810export function NextUploadButton ( props : {
911 disabled ?: boolean ;
1012 scene ?: IReflectNodeReference ;
1113 app ?: any ;
1214} ) {
1315 const [ isLoading , setIsLoading ] = useState ( false ) ;
16+ const history = useHistory ( ) ;
1417
1518 const register = async ( ) => {
1619 setIsLoading ( true ) ;
@@ -38,27 +41,36 @@ export function NextUploadButton(props: {
3841 } ,
3942 } ) ;
4043 } ;
44+
45+ const onNextClick = async ( ) => {
46+ const authenticated = await isAuthenticated ( ) ;
47+ if ( ! authenticated ) {
48+ PluginSdk . notify ( "Let's Sign in first" ) ;
49+ history . push ( "/signin" ) ;
50+ return ;
51+ }
52+
53+ // if authenticated, we can procceed to next step finally. ;)
54+ register ( )
55+ . then ( ( d ) => {
56+ open ( buildOpenUrlForRegisteredScene ( d . id ) ) ;
57+ } )
58+ . catch ( ( e ) => {
59+ console . error ( "error while registering scene" , e ) ;
60+ PluginSdk . notify (
61+ "Oops. something went wrong. pplease try again. ;)" ,
62+ 3
63+ ) ;
64+ } )
65+ . finally ( ( ) => {
66+ setIsLoading ( false ) ;
67+ } ) ;
68+ } ;
69+
4170 return (
4271 < NextStepButton
4372 disabled = { props . disabled || isLoading }
44- onClick = { ( ) => {
45- register ( )
46- . then ( ( d ) => {
47- open ( buildOpenUrlForRegisteredScene ( d . id ) ) ;
48- } )
49- . catch ( ( e ) => {
50- console . error ( "error while registering scene" , e ) ;
51- PluginSdk . notify (
52- "Oops. something went wrong. pplease try again. ;)" ,
53- 3
54- ) ;
55- } )
56- . finally ( ( ) => {
57- setIsLoading ( false ) ;
58- } ) ;
59- // upload
60- // TODO: the button component should be passed from outer side.
61- } }
73+ onClick = { onNextClick }
6274 >
6375 Next
6476 </ NextStepButton >
@@ -72,7 +84,7 @@ function buildOpenUrlForRegisteredScene(sceneId: string) {
7284const NextStepButton = styled . button `
7385 ${ BlackButton }
7486 /* 2/3 size. 12 is wrapper padding */
75- width: calc(66.666% - 12px);
87+ width: calc(66.666% - 12px); /* FIXME: stupid! */
7688
7789 &:hover {
7890 color: #fff;
0 commit comments