import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import useAsync from '@/shared/hooks/use-async' import { getJSON } from '@/infrastructure/fetch-json' import { OLModalBody, OLModalFooter } from '@/shared/components/ol/ol-modal' import OLForm from '@/shared/components/ol/ol-form' import OLFormGroup from '@/shared/components/ol/ol-form-group' import OLFormControl from '@/shared/components/ol/ol-form-control' import OLRow from '@/shared/components/ol/ol-row' import OLCol from '@/shared/components/ol/ol-col' import OLButton from '@/shared/components/ol/ol-button' import OLIconButton from '@/shared/components/ol/ol-icon-button' import Notification from '@/shared/components/notification' import { debugConsole } from '@/utils/debugging' import { ProjectSyncState, GitSyncModalStatus } from '../../types/git-sync-types' type GitSyncMergeOverviewModalProps = { handleHide: () => void setModalStatus: (modalStatus: GitSyncModalStatus) => void projectSyncState: ProjectSyncState projectId: string commitMessage: string setCommitMessage: (message: string) => void } type GitCommit = { message: string author: { name: string email: string date: string } sha: string } type UnmergedCommitsResponse = { commits: GitCommit[] diverged: boolean isProjectUpdated: boolean } const GitSyncMergeOverviewModal = ({ handleHide, setModalStatus, projectSyncState, projectId, commitMessage, setCommitMessage }: GitSyncMergeOverviewModalProps) => { const { t } = useTranslation() const appName = 'Overleaf' const { data, setData, error, isSuccess, isLoading, runAsync, } = useAsync() const loadUnmergedCommits = () => { setData({}) runAsync(getJSON(`/project/${projectId}/github-sync/merge/overview`)) .then(data => { if (!data) setModalStatus('loading') }) .catch(err => { debugConsole.error(err?.data?.message || err?.message || err) if (err?.info?.statusCode === 403 || err?.info?.statusCode === 404 || err?.info?.statusCode === 401 ) setModalStatus('loading') }) } useEffect(() => { loadUnmergedCommits() }, [projectId, runAsync]) return ( <>

{t('project_linked_to')}:  {projectSyncState.repoFullName}

{isLoading && ( <>
{t('loading')}
)} {isSuccess && ( <>
{data.diverged && ( )}

{t('recent_commits_in_github')}

{data.commits?.length === 0 && (

{t('no_new_commits_in_github')}

)} {data.commits?.length > 0 && (
{data.commits.map((commit: GitCommit) => (
{commit.sha.substring(0, 7)} {commit.message}
by {commit.author.name} <{commit.author.email}>
))}
)} {data.isProjectUpdated && ( <>

{t('sync_project_to_github_explanation', { appName })}

setCommitMessage(e.target.value)} />
)} )} {error && ( )}
setModalStatus('confirm-unlink')} disabled={!isSuccess && error?.info?.statusCode !== 404} > {t('unlink')}
setModalStatus('run-merge')} disabled={!isSuccess} > {t('sync')} {t('close')}
) } export default GitSyncMergeOverviewModal