♻️ Abstraction of specific AddModal component out of the Navbar (#1246)
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
|
import { ComponentType, ElementType } from 'react';
|
||||||
|
|
||||||
import { Button, Flex, Icon, useDisclosure } from "@chakra-ui/react"
|
import { Button, Flex, Icon, useDisclosure } from "@chakra-ui/react"
|
||||||
import { FaPlus } from "react-icons/fa"
|
import { FaPlus } from "react-icons/fa"
|
||||||
|
|
||||||
import AddUser from "../Admin/AddUser"
|
|
||||||
import AddItem from "../Items/AddItem"
|
|
||||||
|
|
||||||
interface NavbarProps {
|
interface NavbarProps {
|
||||||
type: string
|
type: string
|
||||||
|
addModalAs: ComponentType | ElementType
|
||||||
}
|
}
|
||||||
|
|
||||||
const Navbar = ({ type }: NavbarProps) => {
|
const Navbar = ({ type, addModalAs }: NavbarProps) => {
|
||||||
const addUserModal = useDisclosure()
|
const addModal = useDisclosure()
|
||||||
const addItemModal = useDisclosure()
|
|
||||||
|
|
||||||
|
const AddModal = addModalAs
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Flex py={8} gap={4}>
|
<Flex py={8} gap={4}>
|
||||||
@@ -26,12 +26,11 @@ const Navbar = ({ type }: NavbarProps) => {
|
|||||||
variant="primary"
|
variant="primary"
|
||||||
gap={1}
|
gap={1}
|
||||||
fontSize={{ base: "sm", md: "inherit" }}
|
fontSize={{ base: "sm", md: "inherit" }}
|
||||||
onClick={type === "User" ? addUserModal.onOpen : addItemModal.onOpen}
|
onClick={addModal.onOpen}
|
||||||
>
|
>
|
||||||
<Icon as={FaPlus} /> Add {type}
|
<Icon as={FaPlus} /> Add {type}
|
||||||
</Button>
|
</Button>
|
||||||
<AddUser isOpen={addUserModal.isOpen} onClose={addUserModal.onClose} />
|
<AddModal isOpen={addModal.isOpen} onClose={addModal.onClose} />
|
||||||
<AddItem isOpen={addItemModal.isOpen} onClose={addItemModal.onClose} />
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@@ -20,6 +20,7 @@ import { Suspense } from "react"
|
|||||||
import { type UserPublic, UsersService } from "../../client"
|
import { type UserPublic, UsersService } from "../../client"
|
||||||
import ActionsMenu from "../../components/Common/ActionsMenu"
|
import ActionsMenu from "../../components/Common/ActionsMenu"
|
||||||
import Navbar from "../../components/Common/Navbar"
|
import Navbar from "../../components/Common/Navbar"
|
||||||
|
import AddUser from "../../components/Admin/AddUser"
|
||||||
|
|
||||||
export const Route = createFileRoute("/_layout/admin")({
|
export const Route = createFileRoute("/_layout/admin")({
|
||||||
component: Admin,
|
component: Admin,
|
||||||
@@ -93,7 +94,7 @@ function Admin() {
|
|||||||
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
|
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
|
||||||
User Management
|
User Management
|
||||||
</Heading>
|
</Heading>
|
||||||
<Navbar type={"User"} />
|
<Navbar type={"User"} addModalAs={AddUser}/>
|
||||||
<TableContainer>
|
<TableContainer>
|
||||||
<Table fontSize="md" size={{ base: "sm", md: "md" }}>
|
<Table fontSize="md" size={{ base: "sm", md: "md" }}>
|
||||||
<Thead>
|
<Thead>
|
||||||
|
@@ -20,6 +20,7 @@ import { useEffect } from "react"
|
|||||||
import { ItemsService } from "../../client"
|
import { ItemsService } from "../../client"
|
||||||
import ActionsMenu from "../../components/Common/ActionsMenu"
|
import ActionsMenu from "../../components/Common/ActionsMenu"
|
||||||
import Navbar from "../../components/Common/Navbar"
|
import Navbar from "../../components/Common/Navbar"
|
||||||
|
import AddItem from "../../components/Items/AddItem"
|
||||||
|
|
||||||
const itemsSearchSchema = z.object({
|
const itemsSearchSchema = z.object({
|
||||||
page: z.number().catch(1),
|
page: z.number().catch(1),
|
||||||
@@ -135,7 +136,7 @@ function Items() {
|
|||||||
Items Management
|
Items Management
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Navbar type={"Item"} />
|
<Navbar type={"Item"} addModalAs={AddItem}/>
|
||||||
<ItemsTable />
|
<ItemsTable />
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user