Skip to content

Commit

Permalink
fix(ui): close modal on create org
Browse files Browse the repository at this point in the history
  • Loading branch information
dorian-grst committed Oct 28, 2024
1 parent 9c87649 commit 42731ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/app/(gistLayout)/layout-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function GistLayout({ avatar, children, username, onMyGists, onCr
const [gistName, setGistName] = useState('')
const [gistContent, setGistContent] = useState('')
const [orgName, setOrgName] = useState('')
const [isOrgModalOpen, setIsOrgModalOpen] = useState(false)

const language = getLanguage(gistName)

Expand Down Expand Up @@ -78,6 +79,8 @@ export default function GistLayout({ avatar, children, username, onMyGists, onCr
My Gists
</MenuButton>
<Modal
open={isOrgModalOpen}
onOpenChange={setIsOrgModalOpen}
trigger={
<MenuButton icon={<PlusIcon />} variant="menu" size="menu" letter="T" className="w-full">
Create org
Expand All @@ -90,11 +93,19 @@ export default function GistLayout({ avatar, children, username, onMyGists, onCr
</div>
}
footer={
<MenuButton variant="default" size="sm" onClick={() => onCreateOrg(orgName)} className="">
<MenuButton
variant="default"
size="sm"
onClick={() => {
onCreateOrg(orgName)
setOrgName('')
setIsOrgModalOpen(false)
}}
>
Create
</MenuButton>
}
></Modal>
/>
</div>
<OrgListFeature />
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/components/ui/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '../shadcn/dialog'
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '../shadcn/dialog'

interface ModalProps {
trigger: React.ReactNode
content: React.ReactNode
footer: React.ReactNode
title: string
open?: boolean
onOpenChange?: (open: boolean) => void
}

export function Modal({ trigger, title, content, footer }: ModalProps) {
export function Modal({ trigger, title, content, footer, open, onOpenChange }: ModalProps) {
return (
<Dialog>
<DialogTrigger asChild>
{trigger}
</DialogTrigger>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent className="gap-0" aria-describedby={undefined}>
<DialogHeader>
<DialogTitle className="text-sm p-3">{title}</DialogTitle>
Expand Down

0 comments on commit 42731ff

Please sign in to comment.