generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #70 from the-collab-lab/dialogs
Merge dialogs branch into main
- Loading branch information
Showing
9 changed files
with
173 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import Loading from './Loading'; | ||
|
||
const Confirm = ({ open, onClose, onConfirm, children, title, loading }) => { | ||
const confirmRef = useRef(null); | ||
const cancelRef = useRef(null); | ||
|
||
// Opens/closes modal depending on open state | ||
useEffect(() => { | ||
const { current: el } = confirmRef; | ||
if (open) { | ||
el.showModal(); | ||
cancelRef.current.focus(); | ||
} else el.close(); | ||
}, [open]); | ||
|
||
return ( | ||
<dialog | ||
className="rounded-md shadow-lg bg-puurWhite text-darkPurple" | ||
ref={confirmRef} | ||
onClose={onClose} | ||
> | ||
<div className="flex flex-col p-8 gap-8"> | ||
<h1 className="text-2xl sm:text-3xl">{title}</h1> | ||
|
||
{loading ? ( | ||
<Loading /> | ||
) : ( | ||
<> | ||
{children} | ||
<div className="flex justify-center content-center flex-wrap gap-4 sm:gap8"> | ||
<button | ||
onClick={onConfirm} | ||
aria-label="Confirm" | ||
className="flex items-center justify-center cursor-pointer bg-lightPurple hover:bg-hoverPurple transition ease-in-out rounded-md text-base sm:text-lg text-puurWhite px-4 py-2 gap-6 shadow-lg min-w-36 sm:min-w-40" | ||
> | ||
<i className="fa-solid fa-check"></i> | ||
Confirm | ||
</button> | ||
<button | ||
onClick={onClose} | ||
aria-label="Cancel" | ||
ref={cancelRef} | ||
className="flex items-center justify-center cursor-pointer border-2 border-darkPurple hover:border-hoverPurple hover:bg-hoverPurple transition ease-in-out rounded-md text-base sm:text-lg text-darkPurple hover:text-puurWhite px-4 py-2 gap-6 shadow-lg min-w-36 sm:min-w-40" | ||
> | ||
<i className="fa-solid fa-x"></i> | ||
Cancel | ||
</button> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
</dialog> | ||
); | ||
}; | ||
|
||
export default Confirm; |
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,45 @@ | ||
import { useState } from 'react'; | ||
import { deleteItem } from '../api/firebase'; | ||
import Confirm from './Confirm'; | ||
|
||
const DeleteItem = ({ itemName, listPath, itemId }) => { | ||
const [open, setOpen] = useState(false); | ||
const [submitted, setSubmitted] = useState(false); | ||
|
||
const handleDelete = (listPath, itemId) => { | ||
setSubmitted(true); | ||
deleteItem(listPath, itemId); | ||
return; | ||
}; | ||
|
||
const openConfirm = () => { | ||
setOpen(true); | ||
}; | ||
const closeConfirm = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={openConfirm} | ||
aria-label={`Delete ${itemName}`} | ||
title={`Delete ${itemName}`} | ||
className="px-2 text-darkPurple rounded-md transition ease-in-out hover:text-alertRed focus:text-alertRed" | ||
> | ||
<i className="fa-solid fa-trash"></i> | ||
</button> | ||
<Confirm | ||
title={`Delete ${itemName.toUpperCase()}`} | ||
onClose={closeConfirm} | ||
onConfirm={() => handleDelete(listPath, itemId)} | ||
open={open} | ||
loading={submitted} | ||
> | ||
{`Do you really want to delete ${itemName.toUpperCase()} from this list?`} | ||
</Confirm> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteItem; |
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,48 @@ | ||
import { useState } from 'react'; | ||
import { deleteList } from '../api/firebase'; | ||
import Confirm from './Confirm'; | ||
|
||
const DeleteList = ({ user, email, listPath, listName, setListPath }) => { | ||
const [open, setOpen] = useState(false); | ||
const [submitted, setSubmitted] = useState(false); | ||
|
||
const handleDelete = (user, email, listPath, listName) => { | ||
setSubmitted(true); | ||
deleteList(user, email, listPath, listName); | ||
setListPath(''); | ||
return; | ||
}; | ||
|
||
const openConfirm = () => { | ||
setOpen(true); | ||
}; | ||
const closeConfirm = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={openConfirm} | ||
aria-label={`Delete ${listName.toUpperCase()}`} | ||
title={`Delete ${listName.toUpperCase()}`} | ||
className="rounded-md transition ease-in-out hover:text-alertRed focus:text-alertRed px-4 py-2" | ||
> | ||
<i className="fa-solid fa-trash"></i> | ||
</button> | ||
<Confirm | ||
title={`Delete ${listName.toUpperCase()} List`} | ||
onClose={closeConfirm} | ||
onConfirm={() => handleDelete(user, email, listPath, listName)} | ||
open={open} | ||
loading={submitted} | ||
> | ||
{listPath.includes(user) | ||
? `Do you really want to delete ${listName.toUpperCase()} list?` | ||
: `Do you really want to stop using ${listName.toUpperCase()} list?`} | ||
</Confirm> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteList; |
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
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
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
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
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
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