Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0cf56b6
run formatter
AltrosMado May 25, 2026
6bb21c9
Merge branch 'staging' of github.com:coding-cat-official/coding-cat i…
AltrosMado May 25, 2026
71fea1c
set edit button to be read only based off db value
AltrosMado May 25, 2026
f13a30e
set readonly on contract through admin dashboard
AltrosMado May 26, 2026
1335f67
create helper functions to get setting for contract
AltrosMado May 26, 2026
9b302cc
Merge branch 'staging' of github.com:coding-cat-official/coding-cat i…
AltrosMado May 26, 2026
08741a3
add user tooltip when contract is readonly
AltrosMado May 26, 2026
c3a41e3
run formatter
AltrosMado May 26, 2026
d80e616
remove unessisary null type check
AltrosMado May 26, 2026
38a8642
create override list w/ working disable logic
AltrosMado May 26, 2026
daadd2e
remove unused function header
AltrosMado May 26, 2026
5a4b29d
add msg if no overrides are active
AltrosMado May 26, 2026
1175708
add contract override to boolean
AltrosMado May 27, 2026
709eb6e
create toggle for contract override
AltrosMado May 27, 2026
bdf807e
update styles
AltrosMado May 27, 2026
c5a0c4a
remove unused button
AltrosMado May 27, 2026
bdc748b
update styles to look even better
AltrosMado May 27, 2026
f3ccdce
Merge branch 'staging' of github.com:coding-cat-official/coding-cat i…
AltrosMado May 27, 2026
7259569
Merge branch 'staging' of github.com:coding-cat-official/coding-cat i…
AltrosMado May 29, 2026
002aa45
stop infinite request loop for overrides
AltrosMado May 29, 2026
a507ebd
Merge branch 'staging' of github.com:coding-cat-official/coding-cat i…
AltrosMado May 29, 2026
818b243
change userData to use StudentRecord
AltrosMado May 29, 2026
7afdc57
make override allow editing the contract even if global readonly is e…
AltrosMado May 29, 2026
19c863d
add missing dependancy
AltrosMado May 29, 2026
8169c7b
remove mentions of student id
AltrosMado May 29, 2026
0a3938e
fix password compare logic not working
AltrosMado May 29, 2026
4f95adb
remove mentions of student id
AltrosMado May 29, 2026
b92f170
set private problems pointer most recent commit
AltrosMado May 29, 2026
b5a8ef9
remove unused imports
AltrosMado May 30, 2026
022b098
Merge branch 'staging' into admin-dashboard
emaj9 Jun 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/components/admin/AdminPageModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Modal, Box, Typography, Switch } from "@mui/joy";
import { ReactNode } from "react";
import { ReactNode, useEffect, useState } from "react";

// Interface for Modal Props
interface AdminPageModalProps {
Expand All @@ -9,6 +9,7 @@ interface AdminPageModalProps {
modalDesc: string;
switchLabel?: string;
switchAction?: () => void;
switchCondition?: () => Promise<boolean>;
extraNodes?: ReactNode[];
}

Expand Down Expand Up @@ -40,8 +41,34 @@ export default function AdminPageModal({
modalDesc,
switchLabel,
switchAction,
switchCondition,
extraNodes: extraNode,
}: AdminPageModalProps) {
const [isChecked, setIsChecked] = useState(false);

// If a switchCondition is set, handle it as a checked condition for the toggle itself
useEffect(() => {
const handleSwitchCondition = async () => {
if (!switchCondition) return;
const fetchedCheckState = await switchCondition();
setIsChecked(fetchedCheckState);
};
handleSwitchCondition();
}, [switchCondition]);

const handleSwitchChange = async () => {
const nextChecked = !isChecked;

setIsChecked(nextChecked);

try {
await switchAction?.();
} catch (error) {
setIsChecked(!nextChecked);
throw error;
}
};

return (
<Modal
open={open}
Expand All @@ -59,7 +86,7 @@ export default function AdminPageModal({
{switchLabel && (
<Typography
component="label"
endDecorator={<Switch onChange={switchAction} />}
endDecorator={<Switch checked={isChecked} onChange={handleSwitchChange} />}
>
{switchLabel}
</Typography>
Expand Down
63 changes: 60 additions & 3 deletions src/components/admin/ContractOverrideList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
export {}
import { Box, Button, List, ListItem, Typography } from "@mui/joy";
import { useEffect, useState } from "react";
import { getProfiles } from "../../utils/getProfiles";
import { StudentRecord } from "../../types";
import { supabase } from "../../supabaseClient";

// export default function ContractOverrideList {
const boxStyles = {
bgcolor: "#b2f2bb",
border: "2px solid",
borderColor: "#006400",
borderRadius: 2,
p: 2,
};

// }
export default function ContractOverrideList() {
const [profilesWithOverrides, setProfilesWithOverrides] = useState<StudentRecord[]>();

useEffect(() => {
const fetchProfileWithOverrides = async () => {
const profiles = await getProfiles("contract_override", "true", "eq");
setProfilesWithOverrides(profiles);
};
fetchProfileWithOverrides();
}, []);

const disableOverride = async (profile_id: string) => {
const { error } = await supabase
.from("profiles")
.update({ contract_override: false })
.eq("profile_id", `${profile_id}`);

if (error) {
throw Error(error.message);
}

// remove the profile from the local list
setProfilesWithOverrides((prev) => prev?.filter((p) => p.profile_id !== profile_id));
};

return (
<Box sx={boxStyles}>
<Typography fontWeight="bold">Students with Write Access Overrides</Typography>
<List>
{profilesWithOverrides && profilesWithOverrides.length > 0 ? (
profilesWithOverrides.map((profile, idx) => (
<ListItem
key={idx}
sx={{ display: "flex", justifyContent: "space-between", width: "100%" }}
>
<Typography>
{profile.username}
</Typography>
<Button onClick={() => disableOverride(profile.profile_id)}> Disable </Button>
</ListItem>
))
) : (
<Typography>No Students Found with Overrides</Typography>
)}
</List>
</Box>
);
}
5 changes: 3 additions & 2 deletions src/components/layout/UpperNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { List as ListIcon } from '@phosphor-icons/react';
import ProfileAvatar from '../profile/ProfileAvatar';
import { ALL_PFPS } from '../profile/UserInfo';
import { Session } from '@supabase/supabase-js';
import { StudentRecord } from '../../types';

interface Props {
openDrawer: () => void;
Expand All @@ -16,7 +17,7 @@ interface Props {
sessionRemainingSeconds: number;
endSession: () => void;
sessionId: string | null;
userData: { name: string; pfp_id: number } | null;
userData: StudentRecord | null;
isAdmin: boolean;
signOut: () => void;
setActiveSession: (param: boolean) => void;
Expand Down Expand Up @@ -86,7 +87,7 @@ export default function UpperNavBar({
) : (
<></>
)}
{userData?.name ?? 'Profile'}
{userData?.username ?? 'Profile'}
</Stack>
</Button>
</Link>
Expand Down
6 changes: 3 additions & 3 deletions src/components/profile/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { supabase } from "../../supabaseClient";
import { Button, Stack, Typography } from "@mui/joy";
import { useOutletContext } from "react-router-dom";
import ProfileAvatar from "./ProfileAvatar";
import { UserData } from "../../types";
import { StudentRecord } from "../../types";

// TODO: maybe get these dynamically?
export const ALL_PFPS = [
Expand All @@ -15,7 +15,7 @@ export const ALL_PFPS = [
"thumbs-up-pfp.png"
]

export default function UserInfo({ userData, refetchProfile }: { userData: UserData | null, refetchProfile: Function }) {
export default function UserInfo({ userData, refetchProfile }: { userData: StudentRecord | null, refetchProfile: Function }) {
const [isUpdating, setIsUpdating] = useState(false);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
Expand Down Expand Up @@ -146,7 +146,7 @@ export default function UserInfo({ userData, refetchProfile }: { userData: UserD
height={pfpHeight}
width={pfpWidth}
/>
{ userData?.name && <Typography level="h2">{userData.name}</Typography> }
{ userData?.username && <Typography level="h2">{userData.username}</Typography> }
<Button onClick={() => { setIsUpdating(true); setSuccess(""); setError(""); }}>
Edit
</Button>
Expand Down
41 changes: 36 additions & 5 deletions src/components/profile/contract/Contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import ContractEdit from "./ContractEdit";
import { supabase } from "../../../supabaseClient";
import { Session } from "@supabase/supabase-js";
import { useOutletContext } from "react-router-dom";
import { fetchContractPerms } from "../../../utils/contractPerms";

interface ContractProps {
categoriesData: CategoryData[];
profileData?: StudentRecord
profileData?: StudentRecord;
}

export default function Contract({ categoriesData, profileData }: ContractProps) {
Expand All @@ -25,7 +26,7 @@ export default function Contract({ categoriesData, profileData }: ContractProps)
const profileId = profileData?.profile_id ?? session?.user.id;

if (!profileId) {
throw Error("Error: No session or profile_id has been defined");
throw Error("Error: No session or profile_id has been defined");
}

// if the categoriesData changes, update the problem count
Expand Down Expand Up @@ -122,6 +123,7 @@ export default function Contract({ categoriesData, profileData }: ContractProps)
setContract={setContract}
featureMap={featureMap}
problemCountByCategory={problemCountByCategory}
profileData={profileData}
/>
</>
);
Expand All @@ -136,6 +138,7 @@ interface ContractModalProps {
onSave: () => Promise<void>;
featureMap: Record<string, boolean>;
problemCountByCategory: Record<string, number>;
profileData?: StudentRecord;
}

function ContractModal({
Expand All @@ -147,8 +150,25 @@ function ContractModal({
onSave,
featureMap,
problemCountByCategory,
profileData
}: ContractModalProps) {
const [isUpdating, setIsUpdating] = useState(false);
const [isReadOnly, setIsReadOnly] = useState(false);

useEffect(() => {
const checkIfReadOnly = async () => {
try {
if(profileData && profileData.contract_override === true){
setIsReadOnly(false)
} else {
setIsReadOnly(await fetchContractPerms());
}
} catch (error) {
console.error("Contract read-only setting could not be loaded", error);
}
};
checkIfReadOnly();
}, [profileData]);

/**
* This function enforces a max and min of submitted values
Expand Down Expand Up @@ -234,9 +254,20 @@ function ContractModal({
</Button>
</>
) : (
<Button sx={{ width: "15%" }} onClick={() => setIsUpdating(true)}>
Edit
</Button>
<>
{isReadOnly && (
<Typography fontWeight="bold" sx={{ mr: 2 }}>
CONTRACT IS SET TO READ-ONLY
</Typography>
)}
<Button
sx={{ width: "15%" }}
onClick={() => setIsUpdating(true)}
disabled={isReadOnly}
>
Edit
</Button>
</>
)}
</Stack>
</ModalDialog>
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useState, useEffect, useCallback } from 'react';
import { supabase } from '../supabaseClient';
import { type Session } from '@supabase/supabase-js';
import { UserData } from '../types';
import { StudentRecord } from '../types';

interface UseAuthReturn {
session: Session | null;
userData: UserData | null;
userData: StudentRecord | null;
isAdmin: boolean;
isRecoverySession: boolean;
fetchProfile: () => Promise<void>;
}

export default function useAuth(): UseAuthReturn {
const [session, setSession] = useState<Session | null>(null);
const [userData, setUserData] = useState<UserData | null>(null);
const [userData, setUserData] = useState<StudentRecord | null>(null);
const [isAdmin, setIsAdmin] = useState(false);
const [isRecoverySession, setIsRecoverySession] = useState(false);

Expand Down Expand Up @@ -71,11 +71,11 @@ export default function useAuth(): UseAuthReturn {
if (!session) return;
const { data } = await supabase
.from('profiles')
.select('username, pfp_id')
.select()
.eq('profile_id', session.user.id)
.single();
if (data) {
setUserData({ name: data.username, pfp_id: data.pfp_id });
setUserData({...data});
}
}, [session]);

Expand Down
6 changes: 3 additions & 3 deletions src/routes/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import OtherStats from "../components/profile/progress/other-stats/OtherStats";
import { useOutletContext } from "react-router-dom";
import SessionReflections from "../components/profile/sessions/SessionReflections";
import useActivityTracker from "../hooks/useActivityTracker";
import { UserData } from "../types";
import { StudentRecord } from "../types";

/**
* The `Account` component handles everything related to the profile page.
* Additional components used in the profile page are located in `components/profile`.
*/
export default function Account({ session }: { session: Session }) {
const { refetchProfile } = useOutletContext<{ refetchProfile: () => Promise<void> }>();
const { userData } = useOutletContext<{ userData: UserData | null }>();
const { userData } = useOutletContext<{ userData: StudentRecord }>();

// Change "reflections" into something else
const [view, setView] = useState<"reflections" | "activity" | "sessions">("reflections");
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function Account({ session }: { session: Session }) {
</Stack>
<Stack direction="column" alignItems="center" gap={1}>
<Typography level="h2">Contract</Typography>
<Contract categoriesData={categoriesData} />
<Contract categoriesData={categoriesData} profileData={userData} />
</Stack>
</Stack>
<Stack marginTop={5} flex={2} gap={2} className="progress-wrapper">
Expand Down
16 changes: 12 additions & 4 deletions src/routes/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import CategoryPasswordForm from "../components/admin/CategoryPasswordForm";
import { ListProtectedCategories } from "../components/admin/ListProtectedCategories";
import { useLoaderData } from "react-router-dom";
import { SearchBar } from "../components/admin/SearchBar";
import { fetchContractPerms, updateContractPerms } from "../utils/contractPerms";
import ContractOverrideList from "../components/admin/ContractOverrideList";

// Defines the data in the modal
interface ModalMetaData {
Expand Down Expand Up @@ -33,8 +35,8 @@ export default function AdminPage() {
const links: ModalMetaData[] = [
{
title: "View Student Information",
desc: "Enter the email/student id of the student you want to a detailed view of",
extraNodes: [<SearchBar />]
desc: "Enter the username of the student you want to a detailed view of",
extraNodes: [<SearchBar />],
},
{
title: "Toggle Public/Test Questions",
Expand All @@ -44,7 +46,12 @@ export default function AdminPage() {
{
title: "Modify Global Contract Permissions",
desc: "Below is a switch that toggles the contract to be read-only globally. This does not apply for student who have contract overrides enabled.",
switch: { switchLabel: "Toggle Read-Only Mode", switchAction: () => ({}) },
switch: {
switchLabel: "Toggle Read-Only Mode",
switchCondition: () => fetchContractPerms(),
switchAction: () => updateContractPerms(),
},
extraNodes: [<ContractOverrideList />]
},
];

Expand All @@ -67,7 +74,7 @@ export default function AdminPage() {
gap: 1.5,
border: "10px, solid ,#d4ff99",
padding: "100px",
marginTop: "5%"
marginTop: "5%",
}}
>
<Typography level="h2" sx={{ marginBottom: 2, color: "black" }}>
Expand All @@ -90,6 +97,7 @@ export default function AdminPage() {
modalDesc={activeModal.desc}
switchLabel={activeModal.switch?.switchLabel}
switchAction={activeModal.switch?.switchAction}
switchCondition={activeModal.switch?.switchCondition}
extraNodes={activeModal.extraNodes}
/>
)}
Expand Down
Loading
Loading