Create Add Pharmacy Modal

This commit is contained in:
abhay-raizada
2024-08-12 17:41:39 +05:30
parent 26e9a80275
commit 605b89c578
8 changed files with 347 additions and 232 deletions

View File

@@ -0,0 +1,112 @@
import {useState} from 'react';
import {Alert, Button, Modal, Text, TextInput, View} from 'react-native';
import {Section} from '../common/Section';
export const AddPharmacy = ({
isVisible,
onClose,
onAdd,
}: {
isVisible: boolean;
onClose: () => void;
onAdd: (npub: string, relay: string, name: string) => void;
}) => {
const [npub, setNpub] = useState('');
const [relay, setRelay] = useState('');
const [name, setName] = useState('');
const handleNpub = (value: string) => {
setNpub(value);
};
const handleRelay = (value: string) => {
setRelay(value);
};
const handleName = (value: string) => {
setName(value);
};
return (
<Modal
visible={isVisible}
onRequestClose={() => {
console.log('closing....');
onClose();
return true;
}}
onDismiss={() => {
onClose();
}}
transparent={true}
style={{backgroundColor: 'black', margin: 0, padding: 0, height: '80%'}}
animationType="slide">
<View
style={{
backgroundColor: 'black',
justifyContent: 'center',
minHeight: '80%',
display: 'flex',
margin: 30,
alignItems: 'center',
}}>
<Section title="Add A Pharmacy">
<View style={{margin: 5}}>
<Text style={{color: 'white', margin: 5}}>Add Pharmacy Name</Text>
<TextInput
style={{
borderColor: '#000000',
borderWidth: 1,
borderRadius: 5,
color: 'white',
}}
placeholderTextColor="grey"
placeholder="Pharmacy X"
onChangeText={handleName}
/>
<Text style={{color: 'white', margin: 5}}>Add Pharmacy Npub</Text>
<TextInput
style={{
borderColor: '#000000',
borderWidth: 1,
borderRadius: 5,
color: 'white',
}}
placeholderTextColor="grey"
placeholder="npub1...."
onChangeText={handleNpub}
/>
<Text style={{color: 'white', margin: 5}}>Add Pharmacy Relay</Text>
<TextInput
style={{
borderColor: '#000000',
borderWidth: 1,
borderRadius: 5,
color: 'white',
}}
placeholderTextColor="grey"
placeholder="wss://<relay-url>"
onChangeText={handleRelay}
/>
</View>
<View style={{flexDirection: 'row'}}>
<View style={{margin: 10}}>
<Button title="Cancel" onPress={() => onClose()}></Button>
</View>
<View style={{margin: 10}}>
<Button
title="Add"
onPress={() => {
if (!npub || !relay || !name)
Alert.alert(
'Missing Inputs',
'Please enter name, npub and relay of the Pharmacy',
);
onAdd(npub, relay, name);
}}></Button>
</View>
</View>
</Section>
</View>
</Modal>
);
};

View File

@@ -0,0 +1,93 @@
import {Dropdown} from 'react-native-element-dropdown';
import {Section} from '../common/Section';
import {Button, Dimensions, Text, View} from 'react-native';
import React, {useState} from 'react';
import {AddPharmacy} from './AddPharmacy';
export const pharmacyData = [
{
label: 'Pharmacy A',
value: 'A',
npub: 'npub1tea09rtjeuzgk4gjajzry37wuyv7h02d4zw38cpadcrkg5yt0qhqncr7km',
relays: ['wss://relay.damus.io'],
},
{
label: ' + Add Pharmacy',
value: 'custom',
},
];
let width = Dimensions.get('window').width;
interface PharmacyPickerProps {
handleLocationChange: (item: any) => void;
}
export const PharmacyPicker: React.FC<PharmacyPickerProps> = ({
handleLocationChange,
}) => {
const [showAddPharmacyModal, setShowAddPharmacyModal] = useState(false);
const renderItem = (item: any) => {
if (item.value === 'custom') {
return (
<View>
<Button
title="Add Pharmacy"
onPress={() => {
setShowAddPharmacyModal(true);
}}
/>
</View>
);
}
return (
<View
style={{
width: width,
display: 'flex',
flexDirection: 'column',
padding: 10,
flexWrap: 'wrap',
}}>
<Text style={{color: 'black', fontSize: 24}}>{item.label}</Text>
<View style={{width: width - 100}}>
<Text style={{color: 'grey', paddingBottom: 5}}>
Npub: {item.npub}
</Text>
<Text style={{color: 'grey'}}>Relays: {item.relays.join(', ')}</Text>
</View>
</View>
);
};
return (
<View>
<Section title="Choose a Pharmacy">
<View style={{width: width - 40}}>
<Dropdown
data={pharmacyData}
labelField={'label'}
valueField={'label'}
onChange={handleLocationChange}
value={pharmacyData[0]}
renderItem={renderItem}
style={{width: '100%'}}
placeholderStyle={{color: 'white'}}
selectedTextStyle={{color: 'white'}}
/>
</View>
</Section>
<AddPharmacy
isVisible={showAddPharmacyModal}
onClose={() => {
setShowAddPharmacyModal(false);
}}
onAdd={() => {
setShowAddPharmacyModal(false);
}}
/>
</View>
);
};