Skip to content

Commit

Permalink
Tony bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky Raup authored and Ricky Raup committed Apr 16, 2024
1 parent 6ecfc9b commit 1218f5a
Show file tree
Hide file tree
Showing 16 changed files with 23,698 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"editor.formatOnSave": false
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
22 changes: 18 additions & 4 deletions client/src/AdminDashboard/PromoteUserButton.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useState } from 'react';
import Button from '@mui/material/Button';
import { upgradePrivilege } from './api';
import { upgradePrivilege, downgradePrivilege } from './api';
import LoadingButton from '../components/buttons/LoadingButton';
import ConfirmationModal from '../components/ConfirmationModal';

interface PromoteUserButtonProps {
admin: boolean;
email: string;
updateAdmin: (email: string) => void;
removeAdmin: (email: string) => void;
}

/**
Expand All @@ -23,6 +24,7 @@ function PromoteUserButton({
admin,
email,
updateAdmin,
removeAdmin,
}: PromoteUserButtonProps) {
const [isLoading, setLoading] = useState(false);

Expand All @@ -33,6 +35,15 @@ function PromoteUserButton({
}
setLoading(false);
}

async function handleDemote() {
setLoading(true);
if (await downgradePrivilege(email)) {
removeAdmin(email);
}
setLoading(false);
}

if (isLoading) {
return <LoadingButton />;
}
Expand All @@ -47,9 +58,12 @@ function PromoteUserButton({
);
}
return (
<Button variant="outlined" disabled>
Already Admin
</Button>
<ConfirmationModal
buttonText="Demote User"
title="Are you sure you want to demote this user from admin?"
body="This action will remove this user's admin privileges"
onConfirm={() => handleDemote()}
/>
);
}

Expand Down
14 changes: 14 additions & 0 deletions client/src/AdminDashboard/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ function UserTable() {
);
};

const removeAdmin = (email: string) => {
setUserList(
userList.map((entry) => {
if (entry.email !== email) {
return entry;
}
const newEntry = entry;
newEntry.admin = false;
return newEntry;
}),
);
};

const enableUser = (email: string) => {
setUserList(
userList.map((entry) => {
Expand Down Expand Up @@ -130,6 +143,7 @@ function UserTable() {
admin={user.admin}
email={user.email}
updateAdmin={updateAdmin}
removeAdmin={removeAdmin}
/>,
<DeleteUserButton
admin={user.admin}
Expand Down
8 changes: 7 additions & 1 deletion client/src/AdminDashboard/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ async function upgradePrivilege(email: string) {
return true;
}

async function downgradePrivilege(email: string) {
const res = await putData('admin/demote', { email });
if (res.error) return false;
return true;
}

function createInvite(email: string) {
return postData('admin/invite', { email });
}

export { deleteUser, upgradePrivilege, createInvite };
export { deleteUser, upgradePrivilege, downgradePrivilege, createInvite };
8 changes: 4 additions & 4 deletions client/src/AdminPickSheet/PickSheetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function PickSheetTable({ orders }: PickSheetTableProps) {
minute: '2-digit',
})}
</TableCell>
<TableCell align="right">{row.organization}</TableCell>
<TableCell align="right">
<TableCell align="left">{row.organization}</TableCell>
<TableCell align="left">
{row.advanced
? row.dry.map((item: IRetailRescueItem) => (
<div key={item.item}>
Expand All @@ -65,8 +65,8 @@ function PickSheetTable({ orders }: PickSheetTableProps) {
))
: row.dry}
</TableCell>
<TableCell align="right">{row.produce}</TableCell>
<TableCell align="right">
<TableCell align="left">{row.produce}</TableCell>
<TableCell align="left">
{row.advanced
? row.vito.map((item: IRetailRescueItem) => (
<div key={item.item}>
Expand Down
1 change: 1 addition & 0 deletions client/src/NewOrderForm/NewOrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function NewOrderForm({ settings, dates }: NewOrderFormProps) {
.set('minutes', formatedTime.minute());

const order = {
email: user.email,
advanced: settings.advanced,
organization: user.organization,
produce: values.produce,
Expand Down
11 changes: 8 additions & 3 deletions client/src/OrderPage/OrderPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,14 @@ function OrderPage() {
<Stack spacing={2} direction="row">
{admin ? (
<>
<Button variant="contained" onClick={handleApprove}>
Approve
</Button>
{order.status === 'PENDING' && (
<Button
variant="contained"
onClick={handleApprove}
>
Approve
</Button>
)}
<Button
variant="contained"
color="secondary"
Expand Down
Loading

0 comments on commit 1218f5a

Please sign in to comment.