@@ -31,7 +31,44 @@ import { useEditorManagerContext } from '@/features/ide-react/context/editor-man
3131import { Trans } from 'react-i18next'
3232
3333
34- type GitHubSyncModalStatus = 'loading' | 'export' | 'merge' | 'pushSubmit' | 'syncing' | 'conflict'
34+ type GitHubSyncModalStatus = 'loading' | 'export' | 'merge' | 'pushSubmit' | 'syncing' | 'conflict' | 'need-auth'
35+
36+ type GitHubSyncModalNeedAuthProps = {
37+ handleHide : ( ) => void
38+ }
39+
40+ const GitHubSyncModalNeedAuth = ( { handleHide } : GitHubSyncModalNeedAuthProps ) => {
41+ const { t } = useTranslation ( )
42+ const { appName } = getMeta ( 'ol-ExposedSettings' )
43+ return (
44+ < >
45+ < OLModalBody >
46+ < p > { t ( 'link_to_github_description' , { appName } ) } </ p >
47+ </ OLModalBody >
48+ < OLModalFooter >
49+ < OLButton
50+ variant = "secondary"
51+ onClick = { handleHide }
52+ >
53+ { t ( 'close' ) }
54+ </ OLButton >
55+
56+ < OLButton
57+ variant = "primary"
58+ onClick = { ( ) => {
59+ window . open (
60+ '/github-sync/beginAuth' ,
61+ 'githubAuth' ,
62+ 'width=600,height=700'
63+ )
64+ } }
65+ >
66+ { t ( 'link_to_github' ) }
67+ </ OLButton >
68+ </ OLModalFooter >
69+ </ >
70+ )
71+ }
3572
3673type GitHubSyncModalSyncingProps = {
3774 handleHide : ( ) => void
@@ -607,27 +644,53 @@ function GitHubSyncModal({
607644 if ( ! show || ! project || modalStatus !== 'loading' ) {
608645 return
609646 }
610- const fetchGitHubSyncStatus = async ( ) => {
647+
648+ const fetchUserGitHubSyncStatus = async ( ) => {
611649 try {
612- const data = await getJSON ( `/project/${ projectId } /github-sync/status` )
613- if ( data . enabled && data . merge_status === 'success' ) {
614- setModalStatus ( 'merge' )
615- setProjectSyncStatus ( data )
616- } else if ( data . enabled && data . merge_status === 'failure' ) {
617- setModalStatus ( 'conflict' )
618- setProjectSyncStatus ( data )
619- }
620- else {
621- setModalStatus ( 'export' )
650+ const data = await getJSON ( '/user/github-sync/status' )
651+ if ( data . enabled ) {
652+ // fetch project github sync status
653+ const projectStatus = await getJSON ( `/project/${ projectId } /github-sync/status` )
654+ if ( projectStatus . enabled && projectStatus . merge_status === 'success' ) {
655+ setModalStatus ( 'merge' )
656+ setProjectSyncStatus ( projectStatus )
657+ } else if ( projectStatus . enabled && projectStatus . merge_status === 'failure' ) {
658+ setModalStatus ( 'conflict' )
659+ setProjectSyncStatus ( projectStatus )
660+ } else {
661+ setModalStatus ( 'export' )
662+ }
663+ } else {
664+ setModalStatus ( 'need-auth' )
622665 }
623666 } catch ( err : any ) {
624667 console . error ( 'Failed to fetch GitHub sync status' , err )
625668 }
626669 }
627670
628- fetchGitHubSyncStatus ( )
671+ // const fetchGitHubSyncStatus = async () => {
672+ // try {
673+ // const data = await getJSON(`/project/${projectId}/github-sync/status`)
674+ // if (data.enabled && data.merge_status === 'success') {
675+ // setModalStatus('merge')
676+ // setProjectSyncStatus(data)
677+ // } else if (data.enabled && data.merge_status === 'failure') {
678+ // setModalStatus('conflict')
679+ // setProjectSyncStatus(data)
680+ // }
681+ // else {
682+ // setModalStatus('export')
683+ // }
684+ // } catch (err: any) {
685+ // console.error('Failed to fetch GitHub sync status', err)
686+ // }
687+ // }
688+
689+ fetchUserGitHubSyncStatus ( )
629690 } , [ show , modalStatus ] )
630691
692+
693+
631694 useEffect ( ( ) => {
632695 if ( ! show )
633696 setCommitMessage ( '' )
@@ -662,6 +725,9 @@ function GitHubSyncModal({
662725 setModalStatus = { setModalStatus }
663726 />
664727 }
728+ {
729+ modalStatus === 'need-auth' && < GitHubSyncModalNeedAuth handleHide = { handleHide } />
730+ }
665731
666732 </ OLModal >
667733 )
0 commit comments