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 ( { console.log('closing....'); onClose(); return true; }} onDismiss={() => { onClose(); }} transparent={true} style={{backgroundColor: 'black', margin: 0, padding: 0, height: '80%'}} animationType="slide">
Add Pharmacy Name Add Pharmacy Npub Add Pharmacy Relay
); };