Skip to content
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

♻️ Abstraction of specific AddModal component out of the Navbar #1246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions frontend/src/components/Common/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentType, ElementType } from 'react';

import { Button, Flex, Icon, useDisclosure } from "@chakra-ui/react"
import { FaPlus } from "react-icons/fa"

import AddUser from "../Admin/AddUser"
import AddItem from "../Items/AddItem"

interface NavbarProps {
type: string
addModalAs: ComponentType | ElementType
}

const Navbar = ({ type }: NavbarProps) => {
const addUserModal = useDisclosure()
const addItemModal = useDisclosure()
const Navbar = ({ type, addModalAs }: NavbarProps) => {
const addModal = useDisclosure()

const AddModal = addModalAs
return (
<>
<Flex py={8} gap={4}>
Expand All @@ -26,12 +26,11 @@ const Navbar = ({ type }: NavbarProps) => {
variant="primary"
gap={1}
fontSize={{ base: "sm", md: "inherit" }}
onClick={type === "User" ? addUserModal.onOpen : addItemModal.onOpen}
onClick={addModal.onOpen}
>
<Icon as={FaPlus} /> Add {type}
</Button>
<AddUser isOpen={addUserModal.isOpen} onClose={addUserModal.onClose} />
<AddItem isOpen={addItemModal.isOpen} onClose={addItemModal.onClose} />
<AddModal isOpen={addModal.isOpen} onClose={addModal.onClose} />
</Flex>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/_layout/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Suspense } from "react"
import { type UserPublic, UsersService } from "../../client"
import ActionsMenu from "../../components/Common/ActionsMenu"
import Navbar from "../../components/Common/Navbar"
import AddUser from "../../components/Admin/AddUser"

export const Route = createFileRoute("/_layout/admin")({
component: Admin,
Expand Down Expand Up @@ -93,7 +94,7 @@ function Admin() {
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
User Management
</Heading>
<Navbar type={"User"} />
<Navbar type={"User"} addModalAs={AddUser}/>
<TableContainer>
<Table fontSize="md" size={{ base: "sm", md: "md" }}>
<Thead>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/_layout/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useEffect } from "react"
import { ItemsService } from "../../client"
import ActionsMenu from "../../components/Common/ActionsMenu"
import Navbar from "../../components/Common/Navbar"
import AddItem from "../../components/Items/AddItem"

const itemsSearchSchema = z.object({
page: z.number().catch(1),
Expand Down Expand Up @@ -135,7 +136,7 @@ function Items() {
Items Management
</Heading>

<Navbar type={"Item"} />
<Navbar type={"Item"} addModalAs={AddItem}/>
<ItemsTable />
</Container>
)
Expand Down