Created
September 22, 2021 12:36
-
-
Save harrybanda/df83a102eeb68479652ee7abf0b3356c to your computer and use it in GitHub Desktop.
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
import ForgeUI, { ModalDialog, Form, TextField } from "@forge/ui"; | |
import { storage } from "@forge/api"; | |
import uuid from "uuid-random"; | |
export const BookDialog = ({ | |
isOpenModal, | |
setOpenModal, | |
isUpdating, | |
selectedBook, | |
}) => { | |
const onSubmit = async (formData) => { | |
let bookId; | |
if (isUpdating) { | |
bookId = selectedBook.key; | |
} else { | |
bookId = "book_" + uuid(); | |
} | |
await storage.set(bookId, formData); | |
setOpenModal(false); | |
}; | |
return ( | |
isOpenModal && ( | |
<ModalDialog | |
header={isUpdating ? "Update Book" : "Add Book"} | |
onClose={() => setOpenModal(false)} | |
> | |
<Form onSubmit={onSubmit}> | |
<TextField | |
name="bookname" | |
label="Book Name" | |
defaultValue={isUpdating ? selectedBook.value.bookname : ""} | |
/> | |
<TextField | |
name="author" | |
label="Author" | |
defaultValue={isUpdating ? selectedBook.value.author : ""} | |
/> | |
<TextField | |
name="quantity" | |
label="Quantity" | |
defaultValue={isUpdating ? selectedBook.value.quantity : ""} | |
/> | |
<TextField | |
name="price" | |
label="Price" | |
defaultValue={isUpdating ? selectedBook.value.price : ""} | |
/> | |
</Form> | |
</ModalDialog> | |
) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment