-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
280 additions
and
60 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
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,44 @@ | ||
import React, { useState } from "react"; | ||
import Dropdown from "./foundation/Dropdown/Dropdown"; | ||
import Modal from "./foundation/Modal/Modal"; | ||
import Input from "./foundation/Input/Input"; | ||
import Button from "./foundation/Button/Button"; | ||
import Toast from "./foundation/Toast/Toast"; | ||
|
||
import RenameCategory from "./RenameCategory"; | ||
|
||
interface EditActionProps { | ||
handleRenameCategory: (newCategoryName: string) => void; | ||
handleDeleteItems: () => void; | ||
} | ||
|
||
const EditAction: React.FC<EditActionProps> = ({ | ||
handleRenameCategory, | ||
handleDeleteItems, | ||
}) => { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
||
const dropdownOptions = [ | ||
{ | ||
label: "Rename", | ||
action: () => setIsModalOpen(true), | ||
}, | ||
{ | ||
label: "Delete", | ||
action: handleDeleteItems, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<Dropdown options={dropdownOptions} /> | ||
<RenameCategory | ||
isOpen={isModalOpen} | ||
setIsOpen={setIsModalOpen} | ||
handleRenameCategory={handleRenameCategory} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default EditAction; |
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,58 @@ | ||
import React, { useState } from "react"; | ||
import Dropdown from "./foundation/Dropdown/Dropdown"; | ||
import Modal from "./foundation/Modal/Modal"; | ||
import Input from "./foundation/Input/Input"; | ||
import Button from "./foundation/Button/Button"; | ||
import Toast from "./foundation/Toast/Toast"; | ||
|
||
interface RenameCategoryProps { | ||
isOpen: boolean; | ||
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
handleRenameCategory: (newCategoryName: string) => void; | ||
} | ||
|
||
const RenameCategory: React.FC<RenameCategoryProps> = ({ | ||
isOpen, | ||
setIsOpen, | ||
handleRenameCategory, | ||
}) => { | ||
const [categoryName, setCategoryName] = useState(""); | ||
const [showToast, setShowToast] = useState<boolean>(false); | ||
|
||
const triggerToast = () => { | ||
setShowToast(true); | ||
setTimeout(() => { | ||
setShowToast(false); | ||
}, 3000); | ||
}; | ||
|
||
const onClickUpdateCategory = () => { | ||
if (categoryName) { | ||
handleRenameCategory(categoryName); | ||
setCategoryName(""); | ||
setIsOpen(false); | ||
} else { | ||
triggerToast(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal isOpen={isOpen} setIsOpen={setIsOpen}> | ||
<Toast show={showToast} message="Invalid name" type="error" /> | ||
<div className="flex flex-col gap-4 p-4"> | ||
<label className="flex justify-between"> | ||
<span>NewCategory</span> | ||
<Input | ||
value={categoryName} | ||
onChange={(e) => setCategoryName(e.target.value)} | ||
/> | ||
</label> | ||
<Button onClick={onClickUpdateCategory} color="black"> | ||
Update | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default RenameCategory; |
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,56 @@ | ||
import React from "react"; | ||
import { Menu } from "@headlessui/react"; | ||
|
||
interface DropdownProps { | ||
options: { label: string; action: () => void }[]; | ||
} | ||
|
||
const Dropdown: React.FC<DropdownProps> = ({ options }) => { | ||
return ( | ||
<div className="shadow-sm"> | ||
<Menu> | ||
{({ open }) => ( | ||
<> | ||
<Menu.Button className="px-3 py-3 rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 bg-white hover:bg-gray-200 border-black text-black"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
strokeWidth={1.5} | ||
stroke="currentColor" | ||
className="w-4 h-4" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" | ||
/> | ||
</svg> | ||
</Menu.Button> | ||
{open && ( | ||
<Menu.Items className="absolute w-24 py-1 mt-1 overflow-auto text-base bg-white border border-gray-300 rounded-md shadow-lg max-h-60 ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm"> | ||
{options.map((option, index) => ( | ||
<Menu.Item key={index}> | ||
{({ active }) => ( | ||
<a | ||
href="#" | ||
className={`${ | ||
active ? "bg-blue-600 text-white" : "text-gray-900" | ||
} block px-4 py-2 text-sm`} | ||
onClick={option.action} | ||
> | ||
{option.label} | ||
</a> | ||
)} | ||
</Menu.Item> | ||
))} | ||
</Menu.Items> | ||
)} | ||
</> | ||
)} | ||
</Menu> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dropdown; |
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,66 @@ | ||
import React from "react"; | ||
import { Dialog, Transition } from "@headlessui/react"; | ||
|
||
interface ModalProps { | ||
isOpen: boolean; | ||
setIsOpen: (value: boolean) => void; | ||
children: React.ReactNode; | ||
} | ||
|
||
const Modal: React.FC<ModalProps> = ({ isOpen, setIsOpen, children }) => { | ||
return ( | ||
<Transition.Root show={isOpen} as={React.Fragment}> | ||
<Dialog | ||
as="div" | ||
static | ||
className="fixed z-10 inset-0 overflow-y-auto" | ||
open={isOpen} | ||
onClose={setIsOpen} | ||
> | ||
<div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"> | ||
<Transition.Child | ||
as={React.Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<Dialog.Overlay className="fixed inset-0 bg-black bg-opacity-50 transition-opacity" /> | ||
</Transition.Child> | ||
|
||
<span | ||
className="hidden sm:inline-block sm:align-middle sm:h-screen" | ||
aria-hidden="true" | ||
> | ||
​ | ||
</span> | ||
|
||
<Transition.Child | ||
as={React.Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
enterTo="opacity-100 translate-y-0 sm:scale-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 translate-y-0 sm:scale-100" | ||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
> | ||
<div className="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6"> | ||
<div> | ||
<div className="flex justify-end items-center"> | ||
<button className="w-6" onClick={() => setIsOpen(false)}> | ||
x | ||
</button> | ||
</div> | ||
{children} | ||
</div> | ||
</div> | ||
</Transition.Child> | ||
</div> | ||
</Dialog> | ||
</Transition.Root> | ||
); | ||
}; | ||
|
||
export default Modal; |
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
aaaf07b
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.
Successfully deployed to the following URLs:
cashly – ./
cashly-irori235.vercel.app
cashly-git-main-irori235.vercel.app
cashly.vercel.app