Skip to content

Commit 987016c

Browse files
wayngoevanugarte
andauthored
Nevermind button (#1992)
* 3 months of lying to wayne * lint max * char city --------- Co-authored-by: evan <evanuxd@gmail.com>
1 parent 26d91c6 commit 987016c

3 files changed

Lines changed: 57 additions & 24 deletions

File tree

api/main_endpoints/routes/PermissionRequest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ router.post('/create', async (req, res) => {
1717
}
1818

1919
try {
20-
await PermissionRequest.create({
20+
const created = await PermissionRequest.create({
2121
userId: decoded.token._id,
2222
type,
2323
status: 'PENDING',
2424
});
25-
res.sendStatus(OK);
25+
res.status(OK).send(created.toJSON());
2626
} catch (error) {
2727
if (error.code === 11000) return res.sendStatus(CONFLICT);
2828
logger.error('Failed to create permission request:', error);
@@ -121,4 +121,3 @@ router.post('/approve', async (req, res) => {
121121
});
122122

123123
module.exports = router;
124-

src/APIFunctions/PermissionRequest.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ export async function createPermissionRequest(type, token) {
4040
body: JSON.stringify({ type }),
4141
});
4242

43-
status.error = !res.ok;
44-
if (res.ok || res.status === 409) {
45-
// Backend sends 200 with no body on success, so fetch the created request
46-
const existingRequest = await getPermissionRequests(type, token);
47-
status.responseData = existingRequest.responseData;
43+
const data = await res.json();
44+
45+
if (res.ok) {
46+
status.responseData = data;
47+
status.error = false;
48+
return status;
49+
}
50+
status.error = true;
51+
if (res.status === 409) {
52+
// user already has a pending/approved request.
53+
status.responseData = data;
4854
}
4955
} catch (err) {
5056
status.responseData = err;

src/Pages/LedSign/LedSign.js

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { healthCheck, updateSignText } from '../../APIFunctions/LedSign';
33
import {
44
getPermissionRequests,
55
createPermissionRequest,
6+
deletePermissionRequest,
67
}from '../../APIFunctions/PermissionRequest';
78
import { useSCE } from '../../Components/context/SceContext';
89
import { membershipState } from '../../Enums';
@@ -259,56 +260,83 @@ function LedSign() {
259260
const result = await createPermissionRequest('LED_SIGN', user.token);
260261
if (!result.error) {
261262
setPermissionRequest({
263+
_id: result.responseData._id,
262264
status: 'PENDING',
263265
});
264266
}
265267
setRequestingPermission(false);
266268
}
267269

268-
function renderPermissionRequestUI() {
269-
if (user.accessLevel >= membershipState.OFFICER) {
270-
return null;
270+
async function handleCancelRequest() {
271+
setRequestingPermission(true);
272+
const result = await deletePermissionRequest(permissionRequest._id, user.token);
273+
if (!result.error) {
274+
setPermissionRequest(null);
271275
}
276+
setRequestingPermission(false);
277+
}
278+
279+
function renderPermissionRequestUI() {
280+
if (user.accessLevel >= membershipState.OFFICER) return null;
281+
282+
// Mobile-friendly container: using max-w-md for better card feel on mobile
283+
const containerClasses = 'w-11/12 sm:w-2/3 lg:w-1/2 text-center p-6 bg-white dark:bg-gray-800 rounded-xl shadow-md space-y-4 fade-in border border-gray-200 dark:border-gray-700';
272284

273285
if (checkingPermission || requestingPermission) {
274286
return (
275-
<div className="w-2/3 lg:w-1/2 text-center py-4">
276-
<p>Loading...</p>
287+
<div className={containerClasses}>
288+
<div className="flex justify-center items-center space-x-2">
289+
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-blue-500"></div>
290+
<p className="text-gray-500">Processing...</p>
291+
</div>
277292
</div>
278293
);
279294
}
280295

281296
if (!permissionRequest) {
282297
return (
283-
<div className="w-2/3 lg:w-1/2 text-center py-4 space-y-2 fade-in">
284-
<p className="text-gray-700 dark:text-gray-300">
285-
You need permission to access the LED sign.
298+
<div className={containerClasses}>
299+
<h2 className="text-xl font-semibold">Access Required</h2>
300+
<p className="text-gray-600 dark:text-gray-400">
301+
You currently do not have permission to update the LED sign. Would you like to request access?
286302
</p>
287303
<button
288-
className="btn bg-blue-500 hover:bg-blue-400 text-white"
304+
className="btn w-full bg-blue-500 hover:bg-blue-400 text-white font-bold py-3 rounded-lg transition-colors"
289305
onClick={handleRequestAccess}
290-
disabled={requestingPermission}
291306
>
292-
{requestingPermission ? 'Requesting...' : 'Request Access'}
307+
Request Access
293308
</button>
294309
</div>
295310
);
296311
}
297312

298313
if (permissionRequest.status === 'PENDING') {
299314
return (
300-
<div className="w-2/3 lg:w-1/2 text-center py-4 space-y-2 fade-in">
315+
<div className={containerClasses}>
316+
<div className="inline-flex items-center justify-center p-2 bg-yellow-100 dark:bg-yellow-900 rounded-full mb-2">
317+
<span className="text-yellow-800 dark:text-yellow-200 text-sm font-bold px-2">Pending Approval</span>
318+
</div>
301319
<p className="text-gray-700 dark:text-gray-300">
302-
You requested access to the sign on {getFormattedTime(permissionRequest.createdAt)}.
320+
Requested on {getFormattedTime(permissionRequest.createdAt)}
303321
</p>
304-
<p className="text-sm text-gray-600 dark:text-gray-400 italic">
305-
Drop a message in Discord to speed up the process!
322+
<p className="text-sm text-gray-500 dark:text-gray-400 italic">
323+
Check back soon! You can also message us on Discord to speed this up.
306324
</p>
325+
326+
{/* Mobile-friendly Button Stack */}
327+
<div className="flex flex-col gap-2 pt-4">
328+
<button
329+
className="btn w-full bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200"
330+
onClick={handleCancelRequest}
331+
>
332+
Nevermind, Cancel Request
333+
</button>
334+
</div>
307335
</div>
308336
);
309337
}
310338

311-
return <h1>{JSON.stringify(permissionRequest)}</h1>;
339+
return null;
312340
}
313341

314342
function renderSignControls() {

0 commit comments

Comments
 (0)