Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,082 Bytes
63b2074 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import React, { useState, useEffect } from "react";
import { Alert, Box, CircularProgress } from "@mui/material";
const MAX_SUBMISSIONS_PER_WEEK = 10;
function SubmissionLimitChecker({ user, children }) {
const [loading, setLoading] = useState(true);
const [reachedLimit, setReachedLimit] = useState(false);
const [error, setError] = useState(false);
useEffect(() => {
const checkSubmissionLimit = async () => {
if (!user?.username) {
setLoading(false);
return;
}
try {
const response = await fetch(
`/api/models/organization/${user.username}/submissions?days=7`
);
if (!response.ok) {
throw new Error("Failed to fetch submission data");
}
const submissions = await response.json();
console.log(`Recent submissions for ${user.username}:`, submissions);
setReachedLimit(submissions.length >= MAX_SUBMISSIONS_PER_WEEK);
setError(false);
} catch (error) {
console.error("Error checking submission limit:", error);
setError(true);
} finally {
setLoading(false);
}
};
checkSubmissionLimit();
}, [user?.username]);
if (loading) {
return (
<Box sx={{ display: "flex", justifyContent: "center", py: 4 }}>
<CircularProgress />
</Box>
);
}
if (error) {
return (
<Alert
severity="error"
sx={{
mb: 3,
"& .MuiAlert-message": {
fontSize: "1rem",
},
}}
>
Unable to verify submission limits. Please try again in a few minutes.
</Alert>
);
}
if (reachedLimit) {
return (
<Alert
severity="warning"
sx={{
mb: 3,
"& .MuiAlert-message": {
fontSize: "1rem",
},
}}
>
For fairness reasons, you cannot submit more than{" "}
{MAX_SUBMISSIONS_PER_WEEK} models per week. Please try again later.
</Alert>
);
}
return children;
}
export default SubmissionLimitChecker;
|