diff --git a/client/src/components/modals/StoreAdminModal.tsx b/client/src/components/modals/StoreAdminModal.tsx index 3d68378..d1820a9 100644 --- a/client/src/components/modals/StoreAdminModal.tsx +++ b/client/src/components/modals/StoreAdminModal.tsx @@ -2,17 +2,19 @@ import { useState } from "react"; import { Modal, Button, Form, ListGroup, Alert } from "react-bootstrap"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faTrashCan } from "@fortawesome/free-regular-svg-icons"; -import { addStore, deleteStore } from "../../../../types"; +import { faUpRightFromSquare } from "@fortawesome/free-solid-svg-icons"; +import { addStore, deleteStore, Store } from "../../../../types"; type Props = { isOpen: boolean; onClose: () => void; - stores: string[]; - onStoresChanged: (stores: string[]) => void; + stores: Store[]; + onStoresChanged: (stores: Store[]) => void; }; export default function StoreAdminModal({ isOpen, onClose, stores, onStoresChanged }: Readonly) { const [newName, setNewName] = useState(''); + const [newUrl, setNewUrl] = useState(''); const [heslo, setHeslo] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); @@ -22,12 +24,13 @@ export default function StoreAdminModal({ isOpen, onClose, stores, onStoresChang setError(null); setLoading(true); try { - const res = await addStore({ body: { name: newName.trim(), heslo } }); + const res = await addStore({ body: { name: newName.trim(), url: newUrl.trim() || undefined, heslo } }); if (res.error) { setError((res.error as any).error || 'Nastala chyba'); } else if (res.data) { - onStoresChanged(res.data as string[]); + onStoresChanged(res.data as Store[]); setNewName(''); + setNewUrl(''); } } catch (e: any) { setError(e.message || 'Nastala chyba'); @@ -44,7 +47,7 @@ export default function StoreAdminModal({ isOpen, onClose, stores, onStoresChang if (res.error) { setError((res.error as any).error || 'Nastala chyba'); } else if (res.data) { - onStoresChanged(res.data as string[]); + onStoresChanged(res.data as Store[]); } } catch (e: any) { setError(e.message || 'Nastala chyba'); @@ -78,12 +81,20 @@ export default function StoreAdminModal({ isOpen, onClose, stores, onStoresChang
Přidat obchod
+ setNewName(e.target.value)} + onKeyDown={e => { e.stopPropagation(); if (e.key === 'Enter') handleAdd(); }} + />
setNewName(e.target.value)} + type="url" + placeholder="URL na nabídku (volitelné, např. Bolt Food/Wolt)" + value={newUrl} + onChange={e => setNewUrl(e.target.value)} onKeyDown={e => { e.stopPropagation(); if (e.key === 'Enter') handleAdd(); }} />