import { useState } from 'react'; import { Alert, StyleSheet, Switch, View } from 'react-native'; import { useTranslation } from 'react-i18next'; import { Screen } from '@/components/layout/screen'; import { AppText } from '@/components/ui/app-text'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Field } from '@/components/ui/field'; import { apiErrorMessage } from '@/core/api/error-text'; import { useCreateRepo } from '@/features/repositories/settings-queries'; import { useTheme } from '@/theme/theme-provider'; import { spacing } from '@/theme/tokens'; import type { RepositoriesStackParamList } from '@/navigation/types'; import type { ScreenProps } from '@/navigation/typing'; type Props = ScreenProps; /** Create a repository under the authenticated user. */ export function CreateRepoScreen({ navigation }: Props) { const { t } = useTranslation(); const { colors } = useTheme(); const create = useCreateRepo(); const [name, setName] = useState(''); const [description, setDescription] = useState(''); const [isPrivate, setIsPrivate] = useState(false); const [autoInit, setAutoInit] = useState(true); const [submitted, setSubmitted] = useState(false); const nameError = submitted && name.trim().length === 0 ? t('createRepo.nameRequired') : undefined; const submit = () => { setSubmitted(true); if (name.trim().length === 0) return; create.mutate( { name: name.trim(), description: description.trim() || undefined, private: isPrivate, auto_init: autoInit, }, { onSuccess: () => navigation.goBack(), onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)), }, ); }; return ( {t('repositories.private')} {t('createRepo.autoInit')} {t('createRepo.autoInitHelp')} {create.isError ? ( {apiErrorMessage(create.error, t)} ) : null}