-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.tsx
60 lines (55 loc) · 1.62 KB
/
edit.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { useRouter, useSearchParams } from "expo-router";
import React, { useEffect, useState } from "react";
import { StyleSheet, View } from "react-native";
import { IconButton, TextInput } from "react-native-paper";
import { Screen } from "../../../../../components/Screen";
import {
Account,
restoreAccount,
updateCategory,
} from "../../../../../lib/account";
import { createEvent, getEvents } from "../../../../../lib/api";
export default function CategoryEdit(): JSX.Element {
const params = useSearchParams();
const accountId = `${params.id}`;
const nameDefault = decodeURIComponent(`${params.name}`);
const categoryId = `${params.categoryId}`;
const [account, setAccount] = useState<Account | null>(null);
const [name, setName] = useState<string>(nameDefault);
const router = useRouter();
useEffect(() => {
getEvents(accountId)
.then((events) => restoreAccount(events))
.then((account) => setAccount(account));
}, []);
const onClickOk = () => {
if (account === null) return;
const [_, event] = updateCategory(account, categoryId, name);
createEvent(event).then((_) => {
router.back();
});
};
return (
<Screen
options={{
title: "Edit Category",
headerRight: () => <IconButton icon="check" onPress={onClickOk} />,
}}
>
<View style={{ flex: 1, width: "100%" }}>
<TextInput
label="Name"
mode="outlined"
onChangeText={setName}
style={styles.input}
value={name}
/>
</View>
</Screen>
);
}
const styles = StyleSheet.create({
input: {
margin: 16,
},
});