Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand All @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions src/components/Profile/components/OfficeInfoList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,6 +20,7 @@ type Props = {
office_hours: string;
Mail_Location: string;
Mail_Description: string;
AD_Username: string;
};
};

Expand All @@ -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);

Expand Down Expand Up @@ -104,6 +109,22 @@ const OfficeInfoList = ({
</Grid>
}
/>
) : isOfficeAdmin ? (
<ProfileInfoListItem
title="Room:"
contentText={
<Grid container spacing={0} alignItems="center">
<Grid item>
{BuildingDescription || OnCampusRoom
? `${BuildingDescription}, ${OnCampusRoom}`
: 'No office location set'}
</Grid>
<Grid item>
<UpdateOffice username={AD_Username} />
</Grid>
</Grid>
}
/>
) : BuildingDescription || OnCampusRoom ? (
<ProfileInfoListItem title="Room:" contentText={`${BuildingDescription}, ${OnCampusRoom}`} />
) : null;
Expand Down
1 change: 1 addition & 0 deletions src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading