-
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.
feat(unit-user-usage): add initial implementation
- Loading branch information
1 parent
2a38ad1
commit a901ec8
Showing
22 changed files
with
801 additions
and
124 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
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
62 changes: 23 additions & 39 deletions
62
components/projects/EditProjectButton/EditProjectButton.tsx
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 |
---|---|---|
@@ -1,59 +1,43 @@ | ||
import type { ReactNode } from "react"; | ||
import { useState } from "react"; | ||
|
||
import type { ProjectDetail } from "@squonk/data-manager-client"; | ||
import { useGetProject } from "@squonk/data-manager-client/project"; | ||
|
||
import { Edit as EditIcon } from "@mui/icons-material"; | ||
import { Box, IconButton, Tooltip, Typography } from "@mui/material"; | ||
import { EditProjectModal } from "./EditProjectModal"; | ||
|
||
import { ModalWrapper } from "../../modals/ModalWrapper"; | ||
import { PrivateProjectToggle } from "./PrivateProjectToggle"; | ||
import { ProjectAdministrators } from "./ProjectAdministrators"; | ||
import { ProjectEditors } from "./ProjectEditors"; | ||
import { ProjectObservers } from "./ProjectObservers"; | ||
interface ChildProps { | ||
openDialog: () => void; | ||
open: boolean; | ||
} | ||
|
||
export interface EditProjectButtonProps { | ||
/** | ||
* Project to be edited. | ||
* ID of project to be edited. | ||
*/ | ||
projectId: string; | ||
/** | ||
* child render prop | ||
*/ | ||
project: ProjectDetail; | ||
children: (props: ChildProps) => ReactNode; | ||
} | ||
|
||
/** | ||
* Button controlling a modal with options to edit the project editors | ||
*/ | ||
export const EditProjectButton = ({ project }: EditProjectButtonProps) => { | ||
export const EditProjectButton = ({ projectId, children }: EditProjectButtonProps) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
const { data: project } = useGetProject(projectId); | ||
|
||
if (!project) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<Tooltip title={"Edit Project"}> | ||
<span> | ||
<IconButton size="small" sx={{ p: "1px" }} onClick={() => setOpen(!open)}> | ||
<EditIcon /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
|
||
<ModalWrapper | ||
DialogProps={{ maxWidth: "sm", fullWidth: true }} | ||
id="edit-project" | ||
open={open} | ||
submitText="Save" | ||
title="Edit Project" | ||
onClose={() => setOpen(false)} | ||
> | ||
<Typography gutterBottom variant="h5"> | ||
{project.name} | ||
</Typography> | ||
|
||
<PrivateProjectToggle isPrivate={project.private} projectId={project.project_id} /> | ||
|
||
<Box display="flex" flexDirection="column" gap={2}> | ||
<ProjectAdministrators project={project} /> | ||
<ProjectEditors project={project} /> | ||
<ProjectObservers project={project} /> | ||
</Box> | ||
</ModalWrapper> | ||
{children({ openDialog: () => setOpen(true), open })} | ||
|
||
<EditProjectModal open={open} projectId={project.project_id} onClose={() => setOpen(false)} /> | ||
</> | ||
); | ||
}; |
64 changes: 64 additions & 0 deletions
64
components/projects/EditProjectButton/EditProjectModal.tsx
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,64 @@ | ||
import { useGetProject } from "@squonk/data-manager-client/project"; | ||
|
||
import { Box, Typography } from "@mui/material"; | ||
|
||
import { ModalWrapper } from "../../modals/ModalWrapper"; | ||
import { PrivateProjectToggle } from "./PrivateProjectToggle"; | ||
import { ProjectAdministrators } from "./ProjectAdministrators"; | ||
import { ProjectEditors } from "./ProjectEditors"; | ||
import { ProjectObservers } from "./ProjectObservers"; | ||
|
||
export interface EditProjectModalProps { | ||
projectId: string; | ||
open: boolean; | ||
onClose: () => void; | ||
onMemberChange?: () => Promise<void>; | ||
} | ||
|
||
export const EditProjectModal = ({ | ||
open, | ||
projectId, | ||
onClose, | ||
onMemberChange, | ||
}: EditProjectModalProps) => { | ||
const { data: project } = useGetProject(projectId); | ||
|
||
if (project === undefined) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ModalWrapper | ||
DialogProps={{ maxWidth: "sm", fullWidth: true }} | ||
id="edit-project" | ||
open={open} | ||
submitText="Save" | ||
title="Edit Project" | ||
onClose={onClose} | ||
> | ||
<Typography gutterBottom variant="h5"> | ||
{project.name} | ||
</Typography> | ||
|
||
<PrivateProjectToggle isPrivate={project.private} projectId={project.project_id} /> | ||
|
||
<Box display="flex" flexDirection="column" gap={2}> | ||
<ProjectAdministrators | ||
administrators={project.administrators} | ||
projectId={project.project_id} | ||
onChange={onMemberChange} | ||
/> | ||
<ProjectEditors | ||
editors={project.editors} | ||
projectId={project.project_id} | ||
onChange={onMemberChange} | ||
/> | ||
<ProjectObservers | ||
observers={project.observers} | ||
projectId={project.project_id} | ||
onChange={onMemberChange} | ||
/> | ||
</Box> | ||
</ModalWrapper> | ||
); | ||
}; |
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.