"use client"; import { Box, Button, Grid, Paper, Stack, Text, TextInput, Title, } from "@mantine/core"; import { notifications } from "@mantine/notifications"; import Image from "next/image"; import { useParams } from "next/navigation"; import { useEffect, useState } from "react"; export default function DeleteAccount() { const [phoneNumber, setPhoneNumber] = useState(""); const [data, setData] = useState({ description: "", }); const [isLoading, setIsLoading] = useState(false); useEffect(() => { // Hanya di client, setelah mount const urlParams = new URLSearchParams(window.location.search); const phone = urlParams.get("phone"); if (phone) { setPhoneNumber(phone); } }, []); const handlerSubmit = async () => { if (!phoneNumber) { return notifications.show({ title: "Error", message: "Please check your phone number", color: "red", }); } if (!data.description) { return notifications.show({ title: "Error", message: "Please fill in description with 'Delete Account'", color: "red", }); } if (data.description !== "Delete Account") { return notifications.show({ title: "Error", message: "Please fill in description with 'Delete Account'", color: "red", }); } try { setIsLoading(true); const response = await fetch("/api/helper/delete-account", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ number: phoneNumber, description: data.description, }), }); const result = await response.json(); if (result.success) { notifications.show({ title: "Success", message: "Account will process to delete", color: "green", }); setData({ description: "", }); } if (!result.success) { notifications.show({ title: "Error", message: result.error || "Failed to delete account.", color: "red", }); } } catch (error) { console.log(error); } finally { setIsLoading(false); } }; return ( logo Delete Account To delete your account with phone number{" "} {phoneNumber ? `+${phoneNumber}` : ""}. Type your message with subject ‘Delete Account’ { setData({ ...data, description: e.target.value, }); }} /> ); }