-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,097 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,79 @@ | ||
import {useState} from 'react'; | ||
import {useQueryClient} from '@tanstack/react-query'; | ||
import {useCreateGroup} from 'afk_nostr_sdk'; | ||
import {Formik} from 'formik'; | ||
import {Text, View} from 'react-native'; | ||
import {SafeAreaView} from 'react-native-safe-area-context'; | ||
|
||
import {Picker} from '../../../components'; | ||
import {Button, Input} from '../../../components'; | ||
import {useStyles} from '../../../hooks'; | ||
import {useToast} from '../../../hooks/modals'; | ||
import stylesheet from './styles'; | ||
|
||
export const CreateGroup: React.FC = () => { | ||
const styles = useStyles(stylesheet); | ||
const [groupName, setGroupName] = useState(''); | ||
const [groupType, setGroupType] = useState(''); | ||
const {showToast} = useToast(); | ||
const queryClient = useQueryClient(); | ||
const {mutate} = useCreateGroup(); | ||
|
||
const handleSubmit = () => { | ||
// Here you would typically handle the form submission, | ||
// e.g., sending the data to an API | ||
console.log('Submitted:', {groupName, groupType}); | ||
const initialValues = { | ||
groupName: '', | ||
groupType: 'private', | ||
}; | ||
|
||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<View style={styles.card}> | ||
<View style={styles.cardHeader}> | ||
<Text style={styles.cardTitle}>Create a New Group</Text> | ||
<Text style={styles.cardDescription}>Add a new group and set its privacy level.</Text> | ||
</View> | ||
<View style={styles.cardContent}> | ||
<Input | ||
style={styles.input} | ||
placeholderTextColor={styles.input as unknown as string} | ||
placeholder="Enter group name" | ||
value={groupName} | ||
onChangeText={setGroupName} | ||
/> | ||
<Picker | ||
selectedValue={groupType} | ||
onValueChange={(itemValue) => setGroupType(itemValue)} | ||
label="" | ||
> | ||
<Picker.Item label="Public" value="public" /> | ||
<Picker.Item label="Private" value="private" /> | ||
</Picker> | ||
</View> | ||
<Button>Create Group</Button> | ||
</View> | ||
<Formik | ||
initialValues={initialValues} | ||
onSubmit={(values) => { | ||
mutate( | ||
{ | ||
groupType: 'private', | ||
groupName: values.groupName, | ||
}, | ||
{ | ||
onSuccess() { | ||
showToast({type: 'success', title: 'Group Created successfully'}); | ||
queryClient.invalidateQueries({queryKey: ['getAllGroups']}); | ||
}, | ||
onError() { | ||
showToast({ | ||
type: 'error', | ||
title: 'Error! Group could not be created. Please try again later.', | ||
}); | ||
}, | ||
}, | ||
); | ||
}} | ||
> | ||
{({handleChange, handleBlur, handleSubmit, values}) => ( | ||
<View style={styles.card}> | ||
<View style={styles.cardHeader}> | ||
<Text style={styles.cardTitle}>Create a New Group</Text> | ||
<Text style={styles.cardDescription}>Add a new group and set its privacy level.</Text> | ||
</View> | ||
<View style={styles.cardContent}> | ||
<Input | ||
style={styles.input} | ||
placeholderTextColor={styles.input as unknown as string} | ||
placeholder="Enter group name" | ||
value={values.groupName} | ||
onBlur={handleBlur('groupName')} | ||
onChangeText={handleChange('groupName')} | ||
/> | ||
<Picker | ||
selectedValue={values.groupType} | ||
onValueChange={(itemValue) => handleChange('groupType')} | ||
label="" | ||
> | ||
<Picker.Item label="Public" value="public" /> | ||
<Picker.Item label="Private" value="private" /> | ||
</Picker> | ||
</View> | ||
<Button onPress={() => handleSubmit()}>Create Group</Button> | ||
</View> | ||
)} | ||
</Formik> | ||
</SafeAreaView> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.