remove email from authcodes
This commit is contained in:
parent
bc5c2075f4
commit
1710d5d91d
2 changed files with 14 additions and 26 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { AuthService } from '../../../auth/authService.ts'
|
import { AuthService } from '../../../auth/authService.ts'
|
||||||
import { useEffect, useState, useRef, MouseEvent } from 'react'
|
import { useEffect, useState, useRef, MouseEvent, useCallback } from 'react'
|
||||||
import { SignupCode } from '../../../auth/signupCode.ts'
|
import { SignupCode } from '../../../auth/signupCode.ts'
|
||||||
import { Temporal } from '@js-temporal/polyfill'
|
import { Temporal } from '@js-temporal/polyfill'
|
||||||
import Button from '../../../../components/buttons/Button.tsx'
|
import Button from '../../../../components/buttons/Button.tsx'
|
||||||
|
@ -12,25 +12,24 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
||||||
const [codes, setCodes] = useState<SignupCode[]>([])
|
const [codes, setCodes] = useState<SignupCode[]>([])
|
||||||
const [code, setCode] = useState('')
|
const [code, setCode] = useState('')
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState('')
|
||||||
const [email, setEmail] = useState('')
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const dialogRef = useRef<HTMLDialogElement>(null)
|
const dialogRef = useRef<HTMLDialogElement>(null)
|
||||||
const [tooltipPosition, setTooltipPosition] = useState<{ x: number; y: number } | null>(null)
|
const [tooltipPosition, setTooltipPosition] = useState<{ x: number; y: number } | null>(null)
|
||||||
const [activeCode, setActiveCode] = useState<string | null>(null)
|
const [activeCode, setActiveCode] = useState<string | null>(null)
|
||||||
|
|
||||||
const fetchCodes = async () => {
|
const fetchCodes = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setCodes(await authService.listSignupCodes())
|
setCodes(await authService.listSignupCodes())
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch signup codes:', err)
|
console.error('Failed to fetch signup codes:', err)
|
||||||
}
|
}
|
||||||
}
|
}, [authService])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timeoutId = setTimeout(fetchCodes)
|
const timeoutId = setTimeout(fetchCodes)
|
||||||
return () => clearTimeout(timeoutId)
|
return () => clearTimeout(timeoutId)
|
||||||
}, [authService])
|
}, [authService, fetchCodes])
|
||||||
|
|
||||||
const handleCreateCode = async (e: React.FormEvent) => {
|
const handleCreateCode = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
@ -38,12 +37,11 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
||||||
setError(null)
|
setError(null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await authService.createSignupCode(code, email, name)
|
await authService.createSignupCode(code, name)
|
||||||
setCode('')
|
setCode('')
|
||||||
setName('')
|
setName('')
|
||||||
setEmail('')
|
|
||||||
dialogRef.current?.close()
|
dialogRef.current?.close()
|
||||||
fetchCodes() // Refresh the table
|
fetchCodes()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Failed to create signup code')
|
setError(err instanceof Error ? err.message : 'Failed to create signup code')
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -116,7 +114,6 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-left">Code</th>
|
<th className="text-left">Code</th>
|
||||||
<th className="text-left">Email</th>
|
|
||||||
<th className="text-left">Redeemed By</th>
|
<th className="text-left">Redeemed By</th>
|
||||||
<th className="text-left">Expires On</th>
|
<th className="text-left">Expires On</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -134,7 +131,6 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
||||||
{code.code}
|
{code.code}
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td>{code.email}</td>
|
|
||||||
<td>{code.redeemedBy || 'Not redeemed'}</td>
|
<td>{code.redeemedBy || 'Not redeemed'}</td>
|
||||||
<td>{formatDate(code.expiresOn)}</td>
|
<td>{formatDate(code.expiresOn)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -191,19 +187,6 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-4">
|
|
||||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700 mb-1">
|
|
||||||
Email
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
id="email"
|
|
||||||
value={email}
|
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
|
||||||
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-end space-x-2">
|
<div className="flex justify-end space-x-2">
|
||||||
<Button type="button" onClick={closeDialog} secondary>
|
<Button type="button" onClick={closeDialog} secondary>
|
||||||
Cancel
|
Cancel
|
||||||
|
|
|
@ -19,7 +19,12 @@ export class AuthService {
|
||||||
dispatchMessage('auth:logged-in', null)
|
dispatchMessage('auth:logged-in', null)
|
||||||
}
|
}
|
||||||
|
|
||||||
async signup(username: string, password: string, signupCode: string, rememberMe: boolean = false) {
|
async signup(
|
||||||
|
username: string,
|
||||||
|
password: string,
|
||||||
|
signupCode: string,
|
||||||
|
rememberMe: boolean = false,
|
||||||
|
) {
|
||||||
const res = await this.client.POST('/auth/register', {
|
const res = await this.client.POST('/auth/register', {
|
||||||
body: { username, password, signupCode, email: null, rememberMe },
|
body: { username, password, signupCode, email: null, rememberMe },
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
@ -39,9 +44,9 @@ export class AuthService {
|
||||||
dispatchMessage('auth:logged-out', null)
|
dispatchMessage('auth:logged-out', null)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createSignupCode(code: string, email: string, name: string) {
|
async createSignupCode(code: string, name: string) {
|
||||||
const res = await this.client.POST('/auth/signup-codes', {
|
const res = await this.client.POST('/auth/signup-codes', {
|
||||||
body: { code, email, name },
|
body: { code, name },
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue