diff --git a/src/app/dashboard/settings/page.tsx b/src/app/dashboard/settings/page.tsx index 6015f0138..0e22023c1 100644 --- a/src/app/dashboard/settings/page.tsx +++ b/src/app/dashboard/settings/page.tsx @@ -684,135 +684,13 @@ function SettingsPageContent() { const handleSaveDiscord = async () => { if (!settings) return; - setSavingDiscord(true); - try { - const res = await fetch("/api/user/settings", { - method: "PATCH", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ discord_webhook_url: discordWebhook, timezone, discord_muted_until: discordMutedUntil }), - }); - if (res.ok) { - const updated = await res.json(); - setSettings(updated); - setIsDirty(false); - toast.success(discordWebhook === "" ? "Discord Webhook removed" : "Discord settings saved successfully!"); - } else { - const errorData = await res.json(); - toast.error(errorData.error || "Failed to update Discord settings"); - } - } catch (error) { - console.error("Error updating Discord settings:", error); - toast.error("Failed to update Discord settings"); - } finally { - setSavingDiscord(false); - } - }; - - const handleTestDiscord = async () => { - if (!discordWebhook) { - toast.error("Please enter a Webhook URL first"); - return; - } - setTestingDiscord(true); - try { - const res = await fetch("/api/user/settings/discord-test", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ webhookUrl: discordWebhook }), - }); - if (res.ok) { - toast.success("Test notification sent! Check your Discord server."); - } else { - const errorData = await res.json(); - toast.error(errorData.error || "Failed to send test notification"); - } - } catch (error) { - console.error("Error sending test notification:", error); - toast.error("Failed to send test notification"); - } finally { - setTestingDiscord(false); - } - }; - - const handleMuteDiscord = async () => { - if (!settings) return; - const dayLabel = muteDuration === 1 ? "day" : "days"; - const mutedUntil = new Date(); - mutedUntil.setDate(mutedUntil.getDate() + muteDuration); - setSavingDiscord(true); - try { - const res = await fetch("/api/user/settings", { - method: "PATCH", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ discord_muted_until: mutedUntil.toISOString() }), - }); - if (res.ok) { - const updated = await res.json(); - setSettings(updated); - setDiscordMutedUntil(updated.discord_muted_until); - setIsDirty(false); - toast.success("Discord notifications muted for " + muteDuration + " " + dayLabel); - } else { - const err = await res.json(); - toast.error(err.error || "Failed to mute notifications"); - } - } catch (_err) { - console.error("mute error", _err); - toast.error("Failed to mute notifications"); - } finally { - setSavingDiscord(false); - } - }; - - const handleUnmuteDiscord = async () => { - if (!settings) return; - setSavingDiscord(true); - try { - const res = await fetch("/api/user/settings", { - method: "PATCH", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ discord_muted_until: null }), - }); - const updated = await res.json(); - if (!res.ok) { - toast.error(updated.error || "Failed to unmute notifications"); - return; - } - setSettings(updated); - setDiscordMutedUntil(null); - setIsDirty(false); - toast.success("Discord notifications unmuted"); - } catch (_err) { - console.error("unmute error", _err); - toast.error("Failed to unmute notifications"); - } finally { - setSavingDiscord(false); - } - }; - - const copyShareLink = () => { - if (!profileUrl) return; - - if (copyResetTimerRef.current) { - window.clearTimeout(copyResetTimerRef.current); - copyResetTimerRef.current = null; - } - - if (!navigator.clipboard?.writeText) { - toast.error("Clipboard access is not available in this browser."); - return; - } - - navigator.clipboard.writeText(profileUrl).then(() => { + const link = `${window.location.origin}/u/${settings.github_login}`; + navigator.clipboard.writeText(link).then(() => { setCopied(true); toast.success("Link copied successfully!"); - copyResetTimerRef.current = window.setTimeout(() => { - setCopied(false); - copyResetTimerRef.current = null; - }, 2000); - }).catch((err) => { - console.error("Clipboard copy failed:", err); - toast.error("Failed to copy profile URL"); + setTimeout(() => setCopied(false), 2000); + }).catch(() => { + toast.error("Failed to copy link"); }); }; @@ -909,7 +787,6 @@ function SettingsPageContent() { {statusMessage.message} )} - {/* Public Profile Section */}