Skip to content

Commit

Permalink
Disable inputs and selects if the user is teacher
Browse files Browse the repository at this point in the history
  • Loading branch information
akmatoff committed May 24, 2024
1 parent d6800bc commit b4de5b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/shared/CustomInput/CustomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
forwardRef,
} from "react";
import { Input } from "@nextui-org/react";
import useIsTeacher from "@/hooks/useIsTeacher";

interface Props extends InputHTMLAttributes<HTMLInputElement> {
name: string;
Expand All @@ -13,14 +14,25 @@ interface Props extends InputHTMLAttributes<HTMLInputElement> {
placeholder?: string;
label?: string;
errorMessage?: string;
isViewOnly?: boolean;
onChangeCallback?: (value: string) => void;
}

const CustomInput: FC<Props> = forwardRef<HTMLInputElement, Props>(
function InputCustom(
{ value, placeholder, label, type, errorMessage, onChange },
{
value,
placeholder,
label,
type,
errorMessage,
onChange,
isViewOnly = false,
},
ref?
) {
const isTeacher = useIsTeacher();

return (
<Input
classNames={{ inputWrapper: ["bg-bgPrimary"] }}
Expand All @@ -32,6 +44,7 @@ const CustomInput: FC<Props> = forwardRef<HTMLInputElement, Props>(
type={type}
isInvalid={!!errorMessage}
errorMessage={errorMessage}
isDisabled={isViewOnly || isTeacher}
/>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/shared/CustomSelect/CustomSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import useIsTeacher from "@/hooks/useIsTeacher";
import { Select, SelectItem } from "@nextui-org/react";
import { ChangeEventHandler } from "react";

Expand All @@ -6,6 +7,7 @@ interface Props {
placeholder?: string;
label: string;
isLoading?: boolean;
isViewOnly?: boolean;
options: { label: string; value: string }[];
errorMessage?: string;
activeValue: { label?: string; value?: string };
Expand All @@ -20,7 +22,10 @@ function CustomSelect({
placeholder,
isLoading,
onChange,
isViewOnly = false,
}: Props) {
const isTeacher = useIsTeacher();

return (
<Select
label={label}
Expand All @@ -29,6 +34,7 @@ function CustomSelect({
isLoading={isLoading}
errorMessage={errorMessage}
selectedKeys={[activeValue.value || ""]}
isDisabled={isViewOnly || isTeacher}
>
{options.map((option) => (
<SelectItem
Expand Down

0 comments on commit b4de5b7

Please sign in to comment.