-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from abhay-raizada/add_inputs
Add Inputs to main screen
- Loading branch information
Showing
23 changed files
with
724,843 additions
and
2,344 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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+1.17 KB
...drawable-mdpi/node_modules_bang88_reactnativeultimatelistview_src_downarrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.1 KB
...awable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+208 Bytes
.../res/drawable-mdpi/node_modules_reactnativeelementdropdown_src_assets_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+186 Bytes
...n/res/drawable-mdpi/node_modules_reactnativeelementdropdown_src_assets_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import {useState} from 'react'; | ||
import {Alert, Button, Modal, Text, TextInput, View} from 'react-native'; | ||
import {Section} from '../common/Section'; | ||
import {getData, storeData} from '../../utils/localStorage'; | ||
|
||
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); | ||
}; | ||
|
||
async function handleAddClick() { | ||
if (!npub || !relay || !name) { | ||
Alert.alert( | ||
'Missing Inputs', | ||
'Please enter name, npub and relay of the Pharmacy', | ||
); | ||
return; | ||
} | ||
if (npub.length !== 63 || !npub.startsWith('npub1')) { | ||
Alert.alert('Invalid Npub'); | ||
return; | ||
} | ||
let pharmacyListString = (await getData('pharmacyList')) || '[]'; | ||
let pharmacyList = JSON.parse(pharmacyListString) as Array<{ | ||
label: string; | ||
npub: string; | ||
relay: string; | ||
}>; | ||
pharmacyList = [...pharmacyList, {label: name, relay: relay, npub: npub}]; | ||
await storeData('pharmacyList', JSON.stringify(pharmacyList)); | ||
|
||
onAdd(npub, relay, name); | ||
} | ||
|
||
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={handleAddClick}></Button> | ||
</View> | ||
</View> | ||
</Section> | ||
</View> | ||
</Modal> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import {Dropdown} from 'react-native-element-dropdown'; | ||
import {Section} from '../common/Section'; | ||
import {Button, Dimensions, Text, View} from 'react-native'; | ||
import React, {useEffect, useState} from 'react'; | ||
import {AddPharmacy} from './AddPharmacy'; | ||
import {getData} from '../../utils/localStorage'; | ||
|
||
export const pharmacyData = [ | ||
{ | ||
label: 'Default pharmacy', | ||
value: 'default', | ||
npub: 'npub1tea09rtjeuzgk4gjajzry37wuyv7h02d4zw38cpadcrkg5yt0qhqncr7km', | ||
relay: '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 [pharmacyList, setPharmacyList] = useState(pharmacyData); | ||
const [initialized, setInitialized] = useState(false); | ||
|
||
const initialize = async () => { | ||
let pharmacyListString = (await getData('pharmacyList')) || '[]'; | ||
let newPharmacyList = JSON.parse(pharmacyListString); | ||
let storePharmacyList = [...newPharmacyList, ...pharmacyList]; | ||
setPharmacyList(storePharmacyList); | ||
setInitialized(true); | ||
handleLocationChange(storePharmacyList[0]); | ||
}; | ||
useEffect(() => { | ||
if (!initialized) initialize(); | ||
}, []); | ||
|
||
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'}}>Relay: {item.relay}</Text> | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<Section title="Choose a Pharmacy"> | ||
<View style={{width: width - 40}}> | ||
<Dropdown | ||
data={pharmacyList} | ||
labelField={'label'} | ||
valueField={'label'} | ||
onChange={handleLocationChange} | ||
value={pharmacyList[0]} | ||
renderItem={renderItem} | ||
style={{width: '100%'}} | ||
placeholderStyle={{color: 'white'}} | ||
selectedTextStyle={{color: 'white'}} | ||
/> | ||
</View> | ||
</Section> | ||
<AddPharmacy | ||
isVisible={showAddPharmacyModal} | ||
onClose={() => { | ||
setShowAddPharmacyModal(false); | ||
}} | ||
onAdd={() => { | ||
initialize(); | ||
setShowAddPharmacyModal(false); | ||
}} | ||
/> | ||
</View> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {Text, TextInput, View} from 'react-native'; | ||
import {styles, TextTheme} from '../common/styles'; | ||
import {useState} from 'react'; | ||
import {Section} from '../common/Section'; | ||
|
||
interface AddressForm { | ||
address_line_1?: string; | ||
city?: string; | ||
state_province?: string; | ||
postal_code?: string; | ||
country_code?: string; | ||
} | ||
|
||
interface AddressFormProps { | ||
nestedFormCallback: (tag: string, form: Object) => void; | ||
} | ||
|
||
export const AddressForm: React.FC<AddressFormProps> = ({ | ||
nestedFormCallback, | ||
}) => { | ||
const [form, setForm] = useState<AddressForm>({}); | ||
|
||
const handleTextChange = (tag: keyof AddressForm, text: string) => { | ||
let newForm = {...form}; | ||
newForm[tag] = text; | ||
setForm(newForm); | ||
nestedFormCallback('Address', newForm); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<View> | ||
<Text style={TextTheme}>Address Line 1</Text> | ||
<TextInput | ||
style={styles.input} | ||
placeholder="Enter street" | ||
value={form.address_line_1} | ||
placeholderTextColor="white" | ||
onChangeText={(text: string) => | ||
handleTextChange('address_line_1', text) | ||
} | ||
/> | ||
</View> | ||
<View> | ||
<Text style={TextTheme}>City</Text> | ||
<TextInput | ||
style={styles.input} | ||
placeholder="Enter city" | ||
value={form.city} | ||
placeholderTextColor="white" | ||
onChangeText={(text: string) => handleTextChange('city', text)} | ||
/> | ||
</View> | ||
<View> | ||
<Text style={TextTheme}>State Provice</Text> | ||
<TextInput | ||
style={styles.input} | ||
placeholder="enter state..." | ||
value={form.state_province} | ||
placeholderTextColor="white" | ||
onChangeText={(text: string) => | ||
handleTextChange('state_province', text) | ||
} | ||
/> | ||
</View> | ||
<View> | ||
<Text style={TextTheme}>Postal Code</Text> | ||
<TextInput | ||
style={styles.input} | ||
placeholder="Enter postal code..." | ||
value={form.postal_code} | ||
placeholderTextColor="white" | ||
onChangeText={(text: string) => handleTextChange('postal_code', text)} | ||
/> | ||
</View> | ||
<View> | ||
<Text style={TextTheme}>Country Code</Text> | ||
<TextInput | ||
style={styles.input} | ||
placeholder="Enter Country Code..." | ||
value={form.country_code} | ||
placeholderTextColor="white" | ||
onChangeText={(text: string) => | ||
handleTextChange('country_code', text) | ||
} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
}; |
Oops, something went wrong.