generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dialogs #70
Merged
Merged
Dialogs #70
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c02a73c
brought first version of Confirm and Delete components
borjaMarti 278b6c7
Merge branch 'main' into dialogs
borjaMarti 4f82b6e
added new DeleteItem, DeleteList, and Confirm components to substitut…
borjaMarti 1150e26
fixed hover behavior on buttons from List and ManageList views
borjaMarti a48141e
delete unused vars in ListButtons
vivitt 4ed2e5f
fix aria-label in dialog
vivitt f0c8039
changed color palette for Confirm buttons
borjaMarti 601ecc4
changed naming convetion for open state in DeleteList and DeleteItem …
borjaMarti 7a4c168
changed naming convetion for open state in DeleteList and DeleteItem …
borjaMarti f24213e
Merge branch 'main' into dialogs
borjaMarti c4d40b5
Merge branch 'main' into dialogs
borjaMarti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="Confirmar" | ||
className="flex items-center justify-center cursor-pointer border-2 hover:border-alertRed bg-none hover:bg-alertRed hover:text-puurWhite transition ease-in-out rounded-md text-base sm:text-lg text-alertRed 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="Cancelar" | ||
ref={cancelRef} | ||
className="flex items-center justify-center cursor-pointer border-2 border-lightPurple hover:border-hoverPurple 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-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 [isConfirmOpen, setIsConfirmOpen] = useState(false); | ||
const [isSubmitted, setIsSubmitted] = useState(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as IsConfirmed |
||
|
||
const handleDelete = (listPath, itemId) => { | ||
setIsSubmitted(true); | ||
deleteItem(listPath, itemId); | ||
return; | ||
}; | ||
|
||
const openConfirm = () => { | ||
setIsConfirmOpen(true); | ||
}; | ||
const closeConfirm = () => { | ||
setIsConfirmOpen(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={isConfirmOpen} | ||
loading={isSubmitted} | ||
> | ||
{`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 [isConfirmOpen, setIsConfirmOpen] = useState(false); | ||
const [isSubmitted, setIsSubmitted] = useState(false); | ||
|
||
const handleDelete = (user, email, listPath, listName) => { | ||
setIsSubmitted(true); | ||
deleteList(user, email, listPath, listName); | ||
setListPath(''); | ||
return; | ||
}; | ||
|
||
const openConfirm = () => { | ||
setIsConfirmOpen(true); | ||
}; | ||
const closeConfirm = () => { | ||
setIsConfirmOpen(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={isConfirmOpen} | ||
loading={isSubmitted} | ||
> | ||
{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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename IsConfirmed field? Is prefix is not suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!