|
1 |
| -import { StatusBar } from "expo-status-bar"; |
2 |
| -import { Button, StyleSheet, Text, TextInput, View } from "react-native"; |
3 |
| -import { useRouter } from "expo-router"; |
| 1 | +import { StyleSheet } from "react-native"; |
| 2 | +import { Stack, useRouter } from "expo-router"; |
4 | 3 | import { useFacade } from "@/data/facades";
|
5 |
| -import { useState } from "react"; |
| 4 | +import { useState, useEffect } from "react"; |
| 5 | +import { Layout, Button, Input, Text } from "@ui-kitten/components"; |
6 | 6 |
|
7 | 7 | export default function AccountName() {
|
8 | 8 | const router = useRouter();
|
9 | 9 | const facade = useFacade();
|
| 10 | + const activeAccount = facade.getAccount.useQuery({}); |
| 11 | + const renameAccount = facade.renameAccount.useMutation({ |
| 12 | + onSuccess: () => { |
| 13 | + router.dismissAll(); |
| 14 | + }, |
| 15 | + }); |
10 | 16 |
|
11 | 17 | const [newName, setNewName] = useState("");
|
12 | 18 |
|
13 |
| - const activeAccount = facade.getAccount.useQuery({}); |
14 |
| - |
15 |
| - const renameAccount = facade.renameAccount.useMutation(); |
| 19 | + useEffect(() => { |
| 20 | + if (activeAccount.data?.name) { |
| 21 | + setNewName(activeAccount.data.name); |
| 22 | + } |
| 23 | + }, [activeAccount.data?.name]); |
16 | 24 |
|
17 | 25 | return (
|
18 |
| - <View style={styles.container}> |
19 |
| - <Button title="Back" onPress={() => router.dismiss()} /> |
| 26 | + <Layout style={styles.container}> |
| 27 | + <Layout style={styles.contentContainer}> |
| 28 | + <Stack.Screen |
| 29 | + options={{ |
| 30 | + headerTitle: "Account Name", |
| 31 | + }} |
| 32 | + /> |
20 | 33 |
|
21 |
| - <View> |
22 |
| - <Text>Account Name</Text> |
23 |
| - <Text>Current name: {activeAccount.data?.name}</Text> |
24 |
| - <TextInput |
25 |
| - placeholder="New Name" |
| 34 | + <Text category="s1" appearance="hint" style={styles.explanationText}> |
| 35 | + Change the name of your account. This name is only visible to you. |
| 36 | + </Text> |
| 37 | + <Input |
| 38 | + style={styles.input} |
| 39 | + label="Account Name" |
| 40 | + placeholder="Enter account name" |
26 | 41 | value={newName}
|
27 | 42 | onChangeText={setNewName}
|
28 | 43 | />
|
29 |
| - </View> |
30 |
| - <Button |
31 |
| - title="Save" |
32 |
| - onPress={async () => { |
33 |
| - if (!activeAccount.data) { |
34 |
| - return; |
35 |
| - } |
36 |
| - await renameAccount.mutateAsync({ |
37 |
| - name: activeAccount.data?.name, |
38 |
| - newName: newName, |
39 |
| - }); |
40 |
| - router.dismissAll(); |
41 |
| - }} |
42 |
| - /> |
43 |
| - <StatusBar style="auto" /> |
44 |
| - </View> |
| 44 | + <Button |
| 45 | + onPress={async () => { |
| 46 | + if (!activeAccount.data) return; |
| 47 | + renameAccount.mutate({ |
| 48 | + name: activeAccount.data?.name, |
| 49 | + newName: newName, |
| 50 | + }); |
| 51 | + }} |
| 52 | + disabled={renameAccount.isPending} |
| 53 | + > |
| 54 | + {renameAccount.isPending ? "Saving..." : "Save"} |
| 55 | + </Button> |
| 56 | + </Layout> |
| 57 | + </Layout> |
45 | 58 | );
|
46 | 59 | }
|
47 | 60 |
|
48 | 61 | const styles = StyleSheet.create({
|
49 | 62 | container: {
|
50 | 63 | flex: 1,
|
51 |
| - backgroundColor: "#fff", |
52 |
| - alignItems: "center", |
53 |
| - justifyContent: "center", |
| 64 | + }, |
| 65 | + contentContainer: { |
| 66 | + flex: 1, |
| 67 | + padding: 16, |
| 68 | + paddingTop: 32, |
| 69 | + }, |
| 70 | + input: { |
| 71 | + marginBottom: 16, |
| 72 | + }, |
| 73 | + explanationText: { |
| 74 | + textAlign: "center", |
| 75 | + marginBottom: 24, |
| 76 | + paddingHorizontal: 16, |
54 | 77 | },
|
55 | 78 | });
|
0 commit comments