-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Admin] Set hacker score thresholds (#527)
* - Added /set-thresholds route - Added UI inputs in HackerApplicants.tsx - Added /get-thresholds route - Display current thresholds in HackerApplicants.tsx * updates thresholds only if non-empty str is passed * Reverted to using fastapi validation for floats
- Loading branch information
1 parent
7d9e46b
commit 236a36c
Showing
5 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
apps/site/src/app/admin/applicants/components/HackerThresholdInputs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { useState } from "react"; | ||
import axios from "axios"; | ||
|
||
import { | ||
Box, | ||
Button, | ||
Input, | ||
SpaceBetween, | ||
} from "@cloudscape-design/components"; | ||
|
||
import useHackerThresholds from "@/lib/admin/useHackerThresholds"; | ||
|
||
function HackerThresholdInputs() { | ||
const { thresholds } = useHackerThresholds(); | ||
|
||
const [acceptValue, setAcceptValue] = useState(""); | ||
const [waitlistValue, setWaitlistValue] = useState(""); | ||
|
||
const [status, setStatus] = useState(""); | ||
|
||
async function submitThresholds() { | ||
const sentAcceptValue = acceptValue ? acceptValue : -1; | ||
const sentWaitlistValue = waitlistValue ? waitlistValue : -1; | ||
|
||
await axios | ||
.post("/api/admin/set-thresholds", { | ||
accept: sentAcceptValue, | ||
waitlist: sentWaitlistValue, | ||
}) | ||
.then((response) => { | ||
// TODO: Add flashbar or modal to show post status | ||
if (response.status === 200) { | ||
setStatus( | ||
"Successfully updated thresholds. Reload to see changes to applicants.", | ||
); | ||
} else { | ||
setStatus("Failed to update thresholds"); | ||
} | ||
}); | ||
} | ||
|
||
return ( | ||
<SpaceBetween direction="vertical" size="xs"> | ||
{thresholds && ( | ||
<> | ||
<Box variant="awsui-key-label"> | ||
Current Accept Threshold: {thresholds.accept} | ||
</Box> | ||
<Box variant="awsui-key-label"> | ||
Current Waitlist Threshold: {thresholds.waitlist} | ||
</Box> | ||
</> | ||
)} | ||
<Box variant="awsui-key-label">Accept Threshold</Box> | ||
<Input | ||
onChange={({ detail }) => setAcceptValue(detail.value)} | ||
value={acceptValue} | ||
type="number" | ||
inputMode="decimal" | ||
placeholder="Accept Threshold" | ||
step={0.1} | ||
/> | ||
<Box variant="awsui-key-label">Waitlist Threshold</Box> | ||
<Input | ||
onChange={({ detail }) => setWaitlistValue(detail.value)} | ||
value={waitlistValue} | ||
type="number" | ||
inputMode="decimal" | ||
placeholder="Waitlist Threshold" | ||
step={0.1} | ||
/> | ||
<Box variant="p"> | ||
Any score under{" "} | ||
{waitlistValue ? waitlistValue : "the waitlist threshold"} will be | ||
rejected | ||
</Box> | ||
<Button variant="primary" onClick={submitThresholds}> | ||
Update Thresholds | ||
</Button> | ||
{status ? ( | ||
<Box variant="awsui-key-label" color="text-status-warning"> | ||
{status} | ||
</Box> | ||
) : null} | ||
</SpaceBetween> | ||
); | ||
} | ||
|
||
export default HackerThresholdInputs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from "axios"; | ||
import useSWR from "swr"; | ||
|
||
export interface ScoreThresholds { | ||
_id: string; | ||
accept: number; | ||
waitlist: number; | ||
} | ||
|
||
const fetcher = async (url: string) => { | ||
const res = await axios.get<ScoreThresholds>(url); | ||
return res.data; | ||
}; | ||
|
||
function useHackerThresholds() { | ||
const { data, error, isLoading } = useSWR<ScoreThresholds>( | ||
"/api/admin/get-thresholds", | ||
fetcher, | ||
); | ||
|
||
return { thresholds: data, loading: isLoading, error }; | ||
} | ||
|
||
export default useHackerThresholds; |