diff --git a/src/components/Profile/components/OfficeInfoList/UpdateOfficeLocationDialog/index.tsx b/src/components/Profile/components/OfficeInfoList/UpdateOfficeLocationDialog/index.tsx index edc62cbd12..cc0fc1814c 100644 --- a/src/components/Profile/components/OfficeInfoList/UpdateOfficeLocationDialog/index.tsx +++ b/src/components/Profile/components/OfficeInfoList/UpdateOfficeLocationDialog/index.tsx @@ -11,7 +11,11 @@ type Building = { Description: string; }; -const UpdateOffice = () => { +type Props = { + username?: string; +}; + +const UpdateOffice = ({ username }: Props) => { const [open, setOpen] = useState(false); const [room, setRoom] = useState(''); const [building, setBuilding] = useState(''); @@ -24,7 +28,10 @@ const UpdateOffice = () => { const handleSubmit = async () => { try { - await userService.updateOfficeLocation({ BuildingCode: building, RoomNumber: room }); + await userService.updateOfficeLocation( + { BuildingCode: building, RoomNumber: room }, + username, + ); setSnackbar({ message: 'Your office location will update within a couple hours.', severity: 'success', diff --git a/src/components/Profile/components/OfficeInfoList/index.tsx b/src/components/Profile/components/OfficeInfoList/index.tsx index 26c08046ab..c53f2ffdb2 100644 --- a/src/components/Profile/components/OfficeInfoList/index.tsx +++ b/src/components/Profile/components/OfficeInfoList/index.tsx @@ -2,6 +2,8 @@ import { useState } from 'react'; import { Card, CardContent, CardHeader, Grid, List, Typography } from '@mui/material'; import ProfileInfoListItem from '../ProfileInfoListItem'; import styles from './OfficeInfoList.module.css'; +import { useAuthGroups } from 'hooks'; +import { AuthGroup } from 'services/auth'; import UpdateOffice from './UpdateOfficeLocationDialog'; import UpdateOfficeHours from './UpdateOfficeHoursDialog'; import UpdateMail from './UpdateMailDestinationDialog'; @@ -18,6 +20,7 @@ type Props = { office_hours: string; Mail_Location: string; Mail_Description: string; + AD_Username: string; }; }; @@ -32,8 +35,10 @@ const OfficeInfoList = ({ office_hours, Mail_Location, Mail_Description, + AD_Username, }, }: Props) => { + const isOfficeAdmin = useAuthGroups(AuthGroup.OfficeAdmin); const [profOfficeHours, setProfOfficeHours] = useState(office_hours); const [profMailLocation, setProfMailLocation] = useState(Mail_Location); @@ -104,6 +109,22 @@ const OfficeInfoList = ({ } /> + ) : isOfficeAdmin ? ( + + + {BuildingDescription || OnCampusRoom + ? `${BuildingDescription}, ${OnCampusRoom}` + : 'No office location set'} + + + + + + } + /> ) : BuildingDescription || OnCampusRoom ? ( ) : null; diff --git a/src/services/auth.ts b/src/services/auth.ts index c0cc969bad..b6f0aad624 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -114,6 +114,7 @@ export enum AuthGroup { LostAndFoundAdmin = '360-LostAndFoundAdmins-SG', LostAndFoundKiosk = '360-LostAndFoundAssist-SG', LostAndFoundDevelopers = '360-LostAndFound-Developers-SG', + OfficeAdmin = '360-OfficeAdmin-SG', } export { diff --git a/src/services/user.ts b/src/services/user.ts index 5256c325eb..4c997658b5 100644 --- a/src/services/user.ts +++ b/src/services/user.ts @@ -283,8 +283,13 @@ const setPlannedGraduationYear = (value: number | string) => { const updateMailStop = (value: string) => http.put(`profiles/mailstop`, value); -const updateOfficeLocation = (OfficeLocation: OfficeLocationQuery) => - http.put(`profiles/office_location`, OfficeLocation); +const updateOfficeLocation = (officeLocation: OfficeLocationQuery, username?: string) => { + let url = 'profiles/office_location'; + if (username) { + url += `?username=${encodeURIComponent(username)}`; + } + return http.put(url, officeLocation); +}; const updateOfficeHours = (value: string) => http.put(`profiles/office_hours`, value);