Skip to content

Commit

Permalink
Merge pull request #1 from abhay-raizada/add_inputs
Browse files Browse the repository at this point in the history
Add Inputs to main screen
  • Loading branch information
abhay-raizada authored Aug 26, 2024
2 parents 3aae1f5 + ae9f81d commit 58f1458
Show file tree
Hide file tree
Showing 23 changed files with 724,843 additions and 2,344 deletions.
32 changes: 15 additions & 17 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,35 @@
* @format
*/

import React, { useEffect, useState } from 'react';
import { SafeAreaView, ScrollView, StatusBar, StyleSheet } from 'react-native';
import React, {useEffect, useState} from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
} from 'react-native';

import { getFormTemplate } from './formstr/formstr';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import { PrescriptionCreator } from './components/PrescriptionCreator';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import {PrescriptionCreator} from './components/PrescriptionCreator';
import 'react-native-url-polyfill/auto';
import PolyfillCrypto from 'react-native-webview-crypto';

function App(): React.JSX.Element {
const backgroundStyle = {
backgroundColor: Colors.darker,
backgroundColor: 'black',
color: 'white',
};

const [form, setForm] = useState<{} | null>(null);

useEffect(() => {
console.log('inside useeffect');
const fetchForm = async () => {
if (!form) {
console.log('fetchiiiing forrmmm!!!');
let form = await getFormTemplate(
'eb3df1f89653475f0bcbd22da35f8d2f126db8a68a88a7abedc53535c76c39b4',
)
setForm(form);
}
};
fetchForm();
}, [form]);
}, []);

return (
<SafeAreaView style={backgroundStyle}>
<PolyfillCrypto />
<StatusBar
barStyle={'light-content'}
backgroundColor={backgroundStyle.backgroundColor}
Expand Down
969 changes: 969 additions & 0 deletions android/app/src/main/assets/index.android.bundle

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed components/Inputs/Inputs.tsx
Empty file.
129 changes: 129 additions & 0 deletions components/PharmacyPicker/AddPharmacy.tsx
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>
);
};
109 changes: 109 additions & 0 deletions components/PharmacyPicker/index.tsx
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>
);
};
90 changes: 90 additions & 0 deletions components/PrescriptionCreator/AddressForm.tsx
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>
);
};
Loading

0 comments on commit 58f1458

Please sign in to comment.