-
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
78 changed files
with
268 additions
and
261 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,8 +1,8 @@ | ||
import AuthDashboard from "@/app/(auth)/components/AuthDashboard" | ||
import AuthLayout from "@/app/(auth)/components/AuthLayout" | ||
import AuthProvider from "@/app/(auth)/components/AuthProvider" | ||
import LoginForm from "@/app/(auth)/components/LoginForm" | ||
import ChangePasswordForm from "@/app/(auth)/components/ChangePasswordForm" | ||
import LoginForm from "@/app/(auth)/components/forms/LoginForm" | ||
import ChangePasswordForm from "@/app/(auth)/components/forms/ChangePasswordForm" | ||
import UserScopeLabel from "@/app/(auth)/components/UserScopeLabel" | ||
|
||
export { AuthDashboard, AuthLayout, AuthProvider, LoginForm, ChangePasswordForm, UserScopeLabel } |
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
File renamed without changes.
File renamed without changes.
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
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
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
2 changes: 1 addition & 1 deletion
2
...rategies/explanations/ArtificialTears.tsx → ...nt)/health/components/ArtificialTears.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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ontent)/health/InteractiveBodyDiagram.tsx → ...lth/components/InteractiveBodyDiagram.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
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions
18
...nts/commonStrategies/commonStrategies.tsx → ...tent)/health/content/commonStrategies.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
File renamed without changes.
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
139 changes: 139 additions & 0 deletions
139
frontend/app/(content)/manage-users/components/EditUserRoleModal.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,139 @@ | ||
import { IUser, UserScope } from "@aapc/types" | ||
import React, { Dispatch, ForwardedRef, forwardRef, SetStateAction, useState } from "react" | ||
import useModal, { ModalRef } from "@/app/lib/hooks/useModal" | ||
import { useAuth } from "@/app/lib/hooks" | ||
import { Nullable } from "@/app/lib/types" | ||
import { editUserScope } from "@/app/services/user" | ||
import Modal from "@/app/components/modals/components/Modal" | ||
import Select from "react-select" | ||
import Button from "@/app/components/Button" | ||
import icons from "@/app/lib/icons" | ||
|
||
type UserRoleOption = { | ||
value: UserScope[] | ||
label: string | ||
} | ||
|
||
type EditUserRoleModalProps = { | ||
user: IUser, | ||
setUser: Dispatch<SetStateAction<IUser>> | ||
} | ||
|
||
const EditUserRoleModal = forwardRef( | ||
function EditUserRoleModal({ user, setUser }: EditUserRoleModalProps, ref: ForwardedRef<ModalRef>) { | ||
const { token } = useAuth() | ||
const [hidden, setHidden] = useModal(`${user.username}-edit-role`, ref) | ||
const [selectedRole, setSelectedRole] = useState<Nullable<UserRoleOption>>(null) | ||
const [pending, setPending] = useState(false) | ||
const [success, setSuccess] = useState(false) | ||
const [error, setError] = useState<Nullable<string>>(null) | ||
|
||
const roles: UserRoleOption[] = [ | ||
{ | ||
value: [UserScope.user, UserScope.regular], | ||
label: "Regular User" | ||
}, | ||
{ | ||
value: [UserScope.user, UserScope.regular, UserScope.premium], | ||
label: "Premium User" | ||
}, | ||
{ | ||
value: [UserScope.user, UserScope.regular, UserScope.premium, UserScope.maintainer], | ||
label: "Site Maintainer" | ||
}, | ||
{ | ||
value: [UserScope.user, UserScope.regular, UserScope.premium, UserScope.maintainer, UserScope.admin], | ||
label: "Site Admin" | ||
}, | ||
] | ||
|
||
const handleEdit = () => { | ||
setSuccess(false) | ||
setError(null) | ||
if (!selectedRole) return | ||
setPending(true) | ||
editUserScope(user.username, selectedRole.value, { token }).then(r => { | ||
if (r.success) { | ||
setPending(false) | ||
setSuccess(true) | ||
setUser && setUser(r.result) | ||
} else { | ||
setPending(false) | ||
setError(r.message) | ||
} | ||
}) | ||
} | ||
|
||
let currentOption = roles[0] | ||
if (user.scopes.includes(UserScope.admin)) { | ||
currentOption = roles[3] | ||
} else if (user.scopes.includes(UserScope.maintainer)) { | ||
currentOption = roles[2] | ||
} else if (user.scopes.includes(UserScope.premium)) { | ||
currentOption = roles[1] | ||
} | ||
return ( | ||
<Modal modalId={`${user.username}-edit-role`} hidden={hidden} | ||
innerClassName={`flex flex-row gap-x-3 justify-between bg-white`}> | ||
<div className={"grow min-h-72 flex flex-col justify-between"}> | ||
<div> | ||
<p className={"form-label"}>Editing @{user.username}'s role</p> | ||
<Select | ||
options={roles} | ||
isSearchable={true} | ||
className={"min-w-44"} | ||
defaultValue={currentOption} | ||
onChange={e => { | ||
setSelectedRole(e) | ||
}} | ||
/> | ||
<div className={"my-6"}> | ||
<p className={"smallest text-slate-800 mt-4"}> | ||
If you wish to give access for a user to manage site content, grant them the <b | ||
className={"font-semibold"}>Site Maintainer</b> role. | ||
</p> | ||
<p className={"smallest text-red-500 mt-4"}> | ||
Granting other users the <b className={"font-semibold"}>Site Admin</b> role also grants | ||
them the permission to <b className={"font-semibold"}>remove that role from you</b>! | ||
</p> | ||
<p className={"smallest text-red-500 mt-4 font-semibold"}> | ||
Only grant the Site Admin role to users you trust. | ||
</p> | ||
</div> | ||
</div> | ||
<div> | ||
{success && | ||
<p className={"form-success mb-2"}>Successfully edited user scope.</p> | ||
} | ||
{error && | ||
<p className={"form-error mb-2"}>{error}</p> | ||
} | ||
<div className={"flex flex-row gap-x-4"}> | ||
<Button | ||
theme={"secondary"} | ||
icon={icons.back} | ||
text={"Back"} | ||
onClick={() => setHidden(true)} | ||
leftIcon | ||
/> | ||
<Button | ||
theme={"green"} | ||
disabled={pending} | ||
icon={icons.edit} | ||
text={pending ? "Editing..." : "Edit"} | ||
onClick={handleEdit} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<Button | ||
theme={"secondary"} | ||
icon={icons.close} | ||
onClick={() => setHidden(true)} | ||
/> | ||
</Modal> | ||
) | ||
} | ||
) | ||
|
||
export default EditUserRoleModal |
Oops, something went wrong.