Made it so the levels are update also when the user starts a diagnostics exam

This commit is contained in:
Tiago Ribeiro
2023-05-27 17:13:55 +01:00
parent 61758af803
commit fe72b770e9

View File

@@ -45,19 +45,10 @@ export default function Diagnostic({onFinish}: Props) {
});
};
const updateUser = () => {
const updateUser = (callback: () => void) => {
axios
.post("/api/users/update", {focus, levels, isFirstLogin: false})
.then(onFinish)
.catch(() => {
toast.error("Something went wrong, please try again later!", {toastId: "user-update-error"});
});
};
const onPerformDiagnosis = async () => {
axios
.post("/api/users/update", {focus, isFirstLogin: false})
.then(selectExam)
.then(callback)
.catch(() => {
toast.error("Something went wrong, please try again later!", {toastId: "user-update-error"});
});
@@ -103,7 +94,7 @@ export default function Diagnostic({onFinish}: Props) {
))}
</div>
<button
onClick={updateUser}
onClick={() => updateUser(onFinish)}
className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)}
disabled={!Object.keys(levels).every((module) => BAND_SCORES[module as Module].includes(levels[module as keyof typeof levels]))}>
Next
@@ -119,7 +110,7 @@ export default function Diagnostic({onFinish}: Props) {
<button onClick={() => setIsInsert(true)} className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)}>
Insert my IELTS level
</button>
<button onClick={onPerformDiagnosis} className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)}>
<button onClick={() => updateUser(selectExam)} className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)}>
Perform a Diagnosis Test
</button>
</div>