disable nominate when quota 0

This commit is contained in:
2025-08-06 20:57:07 +02:00
parent b45bcf03ab
commit 8448a865a7
+13 -2
View File
@@ -1,5 +1,5 @@
"use client";
import { useState } from "react";
import { useState, useEffect } from "react";
import { Nunito } from "next/font/google";
import { api } from "muzak/data/fetcher";
import { useAnimation } from "muzak/contexts/AnimationContext";
@@ -15,6 +15,7 @@ export default function Nominations() {
const [songURL, setSongURL] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [message, setMessage] = useState("");
const [canNominate, setCanNominate] = useState(true);
const isSpotifyURL =
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}(\?.*)?$/.test(
songURL,
@@ -36,6 +37,14 @@ export default function Nominations() {
}
}
useEffect(() => {
if (quota > 0) {
setCanNominate(true);
} else {
setCanNominate(false);
}
}, [quota]);
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<h1
@@ -61,7 +70,9 @@ export default function Nominations() {
<button
className="w-full rounded bg-blue-500 px-4 py-2 text-center font-bold text-white hover:bg-blue-400 disabled:cursor-not-allowed disabled:bg-gray-500"
type="submit"
disabled={isLoading || !songURL.trim() || !isSpotifyURL}
disabled={
isLoading || !songURL.trim() || !isSpotifyURL || !canNominate
}
onClick={async (e) => {
e.preventDefault();
if (!songURL.trim()) return;