disable nominate when quota 0
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Nunito } from "next/font/google";
|
import { Nunito } from "next/font/google";
|
||||||
import { api } from "muzak/data/fetcher";
|
import { api } from "muzak/data/fetcher";
|
||||||
import { useAnimation } from "muzak/contexts/AnimationContext";
|
import { useAnimation } from "muzak/contexts/AnimationContext";
|
||||||
@@ -15,6 +15,7 @@ export default function Nominations() {
|
|||||||
const [songURL, setSongURL] = useState("");
|
const [songURL, setSongURL] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
|
const [canNominate, setCanNominate] = useState(true);
|
||||||
const isSpotifyURL =
|
const isSpotifyURL =
|
||||||
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}(\?.*)?$/.test(
|
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}(\?.*)?$/.test(
|
||||||
songURL,
|
songURL,
|
||||||
@@ -36,6 +37,14 @@ export default function Nominations() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (quota > 0) {
|
||||||
|
setCanNominate(true);
|
||||||
|
} else {
|
||||||
|
setCanNominate(false);
|
||||||
|
}
|
||||||
|
}, [quota]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
||||||
<h1
|
<h1
|
||||||
@@ -61,7 +70,9 @@ export default function Nominations() {
|
|||||||
<button
|
<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"
|
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"
|
type="submit"
|
||||||
disabled={isLoading || !songURL.trim() || !isSpotifyURL}
|
disabled={
|
||||||
|
isLoading || !songURL.trim() || !isSpotifyURL || !canNominate
|
||||||
|
}
|
||||||
onClick={async (e) => {
|
onClick={async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!songURL.trim()) return;
|
if (!songURL.trim()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user