- API: Actions (workflows/runs/jobs/logs getText), repo create/edit/delete, collaborators, webhooks, branch protections, orgs, packages, user keys/GPG keys/tokens, release create/edit/delete - hooks: features/actions, repositories/settings-queries, features/profile - screens: Actions + run detail (expandable job logs), RepoSettings, Collaborators, Webhooks, Protections, CreateRepo, Organizations, OrgRepos, Packages, Credentials, ReleaseCompose; releases list/detail management - navigation + i18n (en/nl) wired for all new screens
204 lines
6.8 KiB
TypeScript
204 lines
6.8 KiB
TypeScript
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 { ListItem } from '@/components/ui/list-item';
|
|
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
|
import { apiErrorMessage } from '@/core/api/error-text';
|
|
import { useRepository } from '@/features/repositories/queries';
|
|
import {
|
|
useDeleteRepo,
|
|
useUpdateRepo,
|
|
} from '@/features/repositories/settings-queries';
|
|
import { useTheme } from '@/theme/theme-provider';
|
|
import { spacing } from '@/theme/tokens';
|
|
import type { RepositoryStackParamList } from '@/navigation/types';
|
|
import type { ScreenProps } from '@/navigation/typing';
|
|
|
|
type Props = ScreenProps<RepositoryStackParamList, 'RepoSettings'>;
|
|
|
|
type FeatureKey =
|
|
| 'has_issues'
|
|
| 'has_pull_requests'
|
|
| 'has_wiki'
|
|
| 'has_releases'
|
|
| 'has_projects'
|
|
| 'has_packages'
|
|
| 'has_actions';
|
|
|
|
/** Repository settings: metadata, feature toggles, danger zone and sub-sections. */
|
|
export function RepoSettingsScreen({ navigation, route }: Props) {
|
|
const { t } = useTranslation();
|
|
const { colors } = useTheme();
|
|
const { owner, name } = route.params;
|
|
|
|
const repoQuery = useRepository(owner, name);
|
|
const repo = repoQuery.data;
|
|
const updateRepo = useUpdateRepo(owner, name);
|
|
const deleteRepo = useDeleteRepo(owner, name);
|
|
|
|
const [description, setDescription] = useState<string | null>(null);
|
|
const [website, setWebsite] = useState<string | null>(null);
|
|
const [isPrivate, setIsPrivate] = useState<boolean | null>(null);
|
|
const [features, setFeatures] = useState<Partial<Record<FeatureKey, boolean>>>({});
|
|
|
|
if (repoQuery.isPending) return <LoadingView />;
|
|
if (repoQuery.isError) {
|
|
return (
|
|
<ErrorState
|
|
title={t('errors.title')}
|
|
body={apiErrorMessage(repoQuery.error, t)}
|
|
retryLabel={t('common.retry')}
|
|
onRetry={() => void repoQuery.refetch()}
|
|
/>
|
|
);
|
|
}
|
|
if (!repo) return null;
|
|
|
|
const descriptionValue = description ?? repo.description ?? '';
|
|
const websiteValue = website ?? repo.website ?? '';
|
|
const privateValue = isPrivate ?? repo.private ?? false;
|
|
const featureValue = (key: FeatureKey) => features[key] ?? repo[key] ?? true;
|
|
|
|
const save = () => {
|
|
updateRepo.mutate(
|
|
{
|
|
description: descriptionValue,
|
|
website: websiteValue,
|
|
private: privateValue,
|
|
has_issues: featureValue('has_issues'),
|
|
has_pull_requests: featureValue('has_pull_requests'),
|
|
has_wiki: featureValue('has_wiki'),
|
|
has_releases: featureValue('has_releases'),
|
|
has_projects: featureValue('has_projects'),
|
|
has_packages: featureValue('has_packages'),
|
|
has_actions: featureValue('has_actions'),
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
Alert.alert(t('repoSettings.savedTitle'), t('repoSettings.savedBody'));
|
|
},
|
|
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
|
},
|
|
);
|
|
};
|
|
|
|
const confirmDelete = () => {
|
|
Alert.alert(t('repoSettings.deleteTitle'), t('repoSettings.deleteBody', { name }), [
|
|
{ text: t('common.cancel'), style: 'cancel' },
|
|
{
|
|
text: t('common.delete'),
|
|
style: 'destructive',
|
|
onPress: () =>
|
|
deleteRepo.mutate(undefined, {
|
|
onSuccess: () => navigation.getParent()?.goBack(),
|
|
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
|
}),
|
|
},
|
|
]);
|
|
};
|
|
|
|
const featureRows: { key: FeatureKey; label: string }[] = [
|
|
{ key: 'has_issues', label: t('repo.issuesTab') },
|
|
{ key: 'has_pull_requests', label: t('repo.pullsTab') },
|
|
{ key: 'has_wiki', label: t('repo.wiki') },
|
|
{ key: 'has_releases', label: t('releases.title') },
|
|
{ key: 'has_projects', label: t('repoSettings.projects') },
|
|
{ key: 'has_packages', label: t('packages.title') },
|
|
{ key: 'has_actions', label: t('actions.title') },
|
|
];
|
|
|
|
return (
|
|
<Screen scroll padded>
|
|
<Field label={t('repo.description')} value={descriptionValue} onChangeText={setDescription} />
|
|
<Field
|
|
label={t('repoSettings.website')}
|
|
value={websiteValue}
|
|
onChangeText={setWebsite}
|
|
autoCapitalize="none"
|
|
autoCorrect={false}
|
|
/>
|
|
|
|
<Card>
|
|
<View style={styles.switchRow}>
|
|
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
|
{t('repositories.private')}
|
|
</AppText>
|
|
<Switch
|
|
value={privateValue}
|
|
onValueChange={setIsPrivate}
|
|
trackColor={{ true: colors.primary, false: colors.border }}
|
|
/>
|
|
</View>
|
|
</Card>
|
|
|
|
<AppText variant="subheading">{t('repoSettings.features')}</AppText>
|
|
<Card>
|
|
{featureRows.map((row, index) => (
|
|
<View key={row.key} style={[styles.switchRow, index > 0 && styles.spaced]}>
|
|
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
|
{row.label}
|
|
</AppText>
|
|
<Switch
|
|
value={featureValue(row.key)}
|
|
onValueChange={(value) => setFeatures((prev) => ({ ...prev, [row.key]: value }))}
|
|
trackColor={{ true: colors.primary, false: colors.border }}
|
|
/>
|
|
</View>
|
|
))}
|
|
</Card>
|
|
|
|
<Button
|
|
label={t('common.save')}
|
|
onPress={save}
|
|
loading={updateRepo.isPending}
|
|
fullWidth
|
|
testID="repo-save"
|
|
/>
|
|
|
|
<AppText variant="subheading">{t('repoSettings.sections')}</AppText>
|
|
<Card padded={false} variant="flat">
|
|
<ListItem
|
|
leadingIcon="people"
|
|
title={t('repoSettings.collaborators')}
|
|
onPress={() => navigation.navigate('Collaborators', { owner, name })}
|
|
/>
|
|
<ListItem
|
|
leadingIcon="globe"
|
|
title={t('repoSettings.webhooks')}
|
|
onPress={() => navigation.navigate('Webhooks', { owner, name })}
|
|
/>
|
|
<ListItem
|
|
leadingIcon="shield"
|
|
title={t('repoSettings.protections')}
|
|
onPress={() => navigation.navigate('Protections', { owner, name })}
|
|
divider={false}
|
|
/>
|
|
</Card>
|
|
|
|
<AppText variant="subheading" tone="error">
|
|
{t('repoSettings.dangerZone')}
|
|
</AppText>
|
|
<Button
|
|
label={t('repoSettings.deleteRepo')}
|
|
variant="danger"
|
|
iconLeft="trash"
|
|
loading={deleteRepo.isPending}
|
|
onPress={confirmDelete}
|
|
fullWidth
|
|
/>
|
|
</Screen>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
switchRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: spacing.md },
|
|
switchLabel: { flex: 1 },
|
|
spaced: { marginTop: spacing.md },
|
|
});
|