feat(phase5): deploy keys, profile editing, organization creation
- API: repo deploy keys (list/add/delete), user settings GET/PATCH, org create - hooks: useRepoKeys/useAddRepoKey/useDeleteRepoKey; useUserSettings, useUpdateUserSettings, useCreateOrg - screens: DeployKeys, Profile (edit), CreateOrg; wired into RepoSettings, Settings and Organizations - endpoint body-shape tests for repo update, release, deploy key, user settings, org create and Action run filters (120 tests total)
This commit is contained in:
1 parent
fa1ebc9184
commit
6d0b536009
17 files changed
+738
-8
No files matched your search
@@ -0,0 +1,118 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { useCreateOrg } from '@/features/profile/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { SettingsStackParamList } from '@/navigation/types';
|
||||
|
||||
type Visibility = 'public' | 'limited' | 'private';
|
||||
|
||||
/** Create an organization. */
|
||||
export function CreateOrgScreen() {
|
||||
const { t } = useTranslation();
|
||||
const navigation = useNavigation<NativeStackNavigationProp<SettingsStackParamList>>();
|
||||
const create = useCreateOrg();
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [fullName, setFullName] = useState('');
|
||||
const [location, setLocation] = useState('');
|
||||
const [visibility, setVisibility] = useState<Visibility>('public');
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
|
||||
const usernameError =
|
||||
submitted && username.trim().length === 0 ? t('organizations.usernameRequired') : undefined;
|
||||
|
||||
const submit = () => {
|
||||
setSubmitted(true);
|
||||
if (username.trim().length === 0) return;
|
||||
create.mutate(
|
||||
{
|
||||
username: username.trim(),
|
||||
full_name: fullName.trim() || undefined,
|
||||
location: location.trim() || undefined,
|
||||
visibility,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
Alert.alert(t('organizations.createdTitle'), t('organizations.createdBody'));
|
||||
navigation.goBack();
|
||||
},
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Field
|
||||
label={t('organizations.username')}
|
||||
value={username}
|
||||
onChangeText={setUsername}
|
||||
placeholder={t('organizations.usernamePlaceholder')}
|
||||
showError={Boolean(usernameError)}
|
||||
error={usernameError}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
testID="org-username"
|
||||
/>
|
||||
<Field
|
||||
label={t('profile.fullName')}
|
||||
value={fullName}
|
||||
onChangeText={setFullName}
|
||||
autoCapitalize="words"
|
||||
/>
|
||||
<Field
|
||||
label={t('profile.location')}
|
||||
value={location}
|
||||
onChangeText={setLocation}
|
||||
autoCapitalize="words"
|
||||
/>
|
||||
<View style={styles.visibility}>
|
||||
<AppText variant="label" tone="secondary">
|
||||
{t('organizations.visibility')}
|
||||
</AppText>
|
||||
<View style={styles.visibilityControl}>
|
||||
<SegmentedControl<Visibility>
|
||||
value={visibility}
|
||||
onChange={setVisibility}
|
||||
accessibilityLabel={t('organizations.visibility')}
|
||||
options={[
|
||||
{ value: 'public', label: t('organizations.visPublic') },
|
||||
{ value: 'limited', label: t('organizations.visLimited') },
|
||||
{ value: 'private', label: t('organizations.visPrivate') },
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{create.isError ? (
|
||||
<AppText variant="caption" tone="error">
|
||||
{apiErrorMessage(create.error, t)}
|
||||
</AppText>
|
||||
) : null}
|
||||
|
||||
<Button
|
||||
label={t('organizations.create')}
|
||||
onPress={submit}
|
||||
loading={create.isPending}
|
||||
disabled={username.trim().length === 0}
|
||||
fullWidth
|
||||
testID="org-submit"
|
||||
/>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
visibility: { gap: spacing.xs },
|
||||
visibilityControl: { marginTop: spacing.xs },
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
import { QueryList } from '@/components/layout/query-list';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Avatar } from '@/components/ui/avatar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import type { Organization } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
@@ -25,6 +26,17 @@ export function OrganizationsScreen() {
|
||||
query={query}
|
||||
items={orgs}
|
||||
keyExtractor={(org) => String(org.id ?? org.username)}
|
||||
header={
|
||||
<View style={styles.header}>
|
||||
<Button
|
||||
label={t('organizations.create')}
|
||||
variant="secondary"
|
||||
iconLeft="plus"
|
||||
fullWidth
|
||||
onPress={() => navigation.navigate('CreateOrg')}
|
||||
/>
|
||||
</View>
|
||||
}
|
||||
renderItem={(org) => {
|
||||
const login = org.username ?? org.name ?? '';
|
||||
return (
|
||||
@@ -54,6 +66,7 @@ export function OrganizationsScreen() {
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
header: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm },
|
||||
row: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, 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 { Field } from '@/components/ui/field';
|
||||
import { TextArea } from '@/components/ui/text-area';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import type { UserSettings } from '@/core/api/types';
|
||||
import { useUpdateUserSettings, useUserSettings } from '@/features/profile/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
|
||||
/** Edit the signed-in user's public profile. */
|
||||
export function ProfileScreen() {
|
||||
const { t } = useTranslation();
|
||||
const query = useUserSettings();
|
||||
|
||||
if (query.isPending) return <LoadingView />;
|
||||
if (query.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(query.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void query.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <ProfileForm key={query.dataUpdatedAt} settings={query.data ?? {}} />;
|
||||
}
|
||||
|
||||
function ProfileForm({ settings }: { settings: UserSettings }) {
|
||||
const { t } = useTranslation();
|
||||
const update = useUpdateUserSettings();
|
||||
|
||||
const [fullName, setFullName] = useState(settings.full_name ?? '');
|
||||
const [bio, setBio] = useState(settings.description ?? '');
|
||||
const [website, setWebsite] = useState(settings.website ?? '');
|
||||
const [location, setLocation] = useState(settings.location ?? '');
|
||||
|
||||
const save = () => {
|
||||
update.mutate(
|
||||
{
|
||||
full_name: fullName.trim(),
|
||||
description: bio.trim(),
|
||||
website: website.trim(),
|
||||
location: location.trim(),
|
||||
},
|
||||
{
|
||||
onSuccess: () => Alert.alert(t('repoSettings.savedTitle'), t('profile.savedBody')),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Field label={t('profile.fullName')} value={fullName} onChangeText={setFullName} autoCapitalize="words" />
|
||||
<TextArea
|
||||
label={t('profile.bio')}
|
||||
value={bio}
|
||||
onChangeText={setBio}
|
||||
autoCapitalize="sentences"
|
||||
autoCorrect
|
||||
minHeight={100}
|
||||
/>
|
||||
<Field
|
||||
label={t('repoSettings.website')}
|
||||
value={website}
|
||||
onChangeText={setWebsite}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
/>
|
||||
<Field label={t('profile.location')} value={location} onChangeText={setLocation} autoCapitalize="words" />
|
||||
|
||||
{update.isError ? (
|
||||
<AppText variant="caption" tone="error">
|
||||
{apiErrorMessage(update.error, t)}
|
||||
</AppText>
|
||||
) : null}
|
||||
|
||||
<Button
|
||||
label={t('common.save')}
|
||||
onPress={save}
|
||||
loading={update.isPending}
|
||||
fullWidth
|
||||
testID="profile-save"
|
||||
/>
|
||||
<View style={styles.spacer} />
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
spacer: { height: spacing.xl },
|
||||
});
|
||||
Reference in new issue
Block a user