good forst commit

This commit is contained in:
2026-06-09 02:02:40 +05:30
parent 801c1d7121
commit 249d759e6a
215 changed files with 15425 additions and 1240 deletions
@@ -0,0 +1,44 @@
'use client';
import { useRouter } from 'next/navigation';
import { useState, useTransition } from 'react';
export function DeleteAccountButton() {
const router = useRouter();
const [pending, startTransition] = useTransition();
const [error, setError] = useState<string | null>(null);
function handleClick() {
if (
!window.confirm(
'Permanently delete your TOWER account? This cannot be undone.',
)
) {
return;
}
setError(null);
startTransition(async () => {
const res = await fetch('/api/my/account', { method: 'DELETE' });
if (!res.ok) {
const body = (await res.json().catch(() => ({}))) as { message?: string };
setError(body.message ?? 'Delete failed');
return;
}
router.replace('/');
});
}
return (
<div className="flex flex-col items-start gap-1">
<button
type="button"
onClick={handleClick}
disabled={pending}
className="rounded border border-red-300 bg-white px-3 py-1.5 text-sm text-red-700 hover:bg-red-50 disabled:opacity-50"
>
{pending ? 'Deleting…' : 'Delete my account'}
</button>
{error && <span className="text-xs text-red-700">{error}</span>}
</div>
);
}
@@ -0,0 +1,24 @@
'use client';
import { useRouter } from 'next/navigation';
import { useState, useTransition } from 'react';
export function MemberLogoutButton() {
const router = useRouter();
const [pending, startTransition] = useTransition();
return (
<button
type="button"
disabled={pending}
onClick={() =>
startTransition(async () => {
await fetch('/api/my/logout', { method: 'POST' });
router.replace('/');
})
}
className="rounded border border-gray-300 px-3 py-1.5 text-sm hover:bg-gray-50 disabled:opacity-50"
>
{pending ? 'Signing out…' : 'Sign out'}
</button>
);
}
+36
View File
@@ -0,0 +1,36 @@
import { getMemberToken } from '../../_lib/api';
import { DeleteAccountButton } from './DeleteAccountButton';
import { MemberLogoutButton } from './MemberLogoutButton';
export default async function MySettingsPage() {
const token = await getMemberToken();
if (!token) {
return (
<div className="max-w-2xl mx-auto mt-12 p-6 rounded-lg border border-yellow-200 bg-yellow-50">
<h1 className="text-lg font-semibold text-yellow-800">Sign in required</h1>
<p className="text-sm text-yellow-700">Complete onboarding to manage your account.</p>
</div>
);
}
return (
<div className="max-w-2xl mx-auto mt-12 p-6 flex flex-col gap-6">
<section className="rounded-xl border border-gray-200 bg-white p-5">
<h2 className="text-base font-semibold mb-2">Session</h2>
<p className="text-sm text-gray-600 mb-3">
Sign out of your member portal. Your consent records are kept until you delete your account.
</p>
<MemberLogoutButton />
</section>
<section className="rounded-xl border border-red-200 bg-red-50 p-5">
<h2 className="text-base font-semibold text-red-800 mb-2">Delete your account</h2>
<p className="text-sm text-red-700 mb-3">
This permanently deletes your TOWER user record, all consent records, opt-out history, and
sessions. The messages themselves stay in their original groups. This cannot be undone.
</p>
<DeleteAccountButton />
</section>
</div>
);
}