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 { useEffect, useState, useRef, MouseEvent } from 'react'
|
||||
import { useEffect, useState, useRef, MouseEvent, useCallback } from 'react'
|
||||
import { SignupCode } from '../../../auth/signupCode.ts'
|
||||
import { Temporal } from '@js-temporal/polyfill'
|
||||
import Button from '../../../../components/buttons/Button.tsx'
|
||||
|
@ -12,25 +12,24 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
|||
const [codes, setCodes] = useState<SignupCode[]>([])
|
||||
const [code, setCode] = useState('')
|
||||
const [name, setName] = useState('')
|
||||
const [email, setEmail] = useState('')
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const dialogRef = useRef<HTMLDialogElement>(null)
|
||||
const [tooltipPosition, setTooltipPosition] = useState<{ x: number; y: number } | null>(null)
|
||||
const [activeCode, setActiveCode] = useState<string | null>(null)
|
||||
|
||||
const fetchCodes = async () => {
|
||||
const fetchCodes = useCallback(async () => {
|
||||
try {
|
||||
setCodes(await authService.listSignupCodes())
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch signup codes:', err)
|
||||
}
|
||||
}
|
||||
}, [authService])
|
||||
|
||||
useEffect(() => {
|
||||
const timeoutId = setTimeout(fetchCodes)
|
||||
return () => clearTimeout(timeoutId)
|
||||
}, [authService])
|
||||
}, [authService, fetchCodes])
|
||||
|
||||
const handleCreateCode = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
|
@ -38,12 +37,11 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
|||
setError(null)
|
||||
|
||||
try {
|
||||
await authService.createSignupCode(code, email, name)
|
||||
await authService.createSignupCode(code, name)
|
||||
setCode('')
|
||||
setName('')
|
||||
setEmail('')
|
||||
dialogRef.current?.close()
|
||||
fetchCodes() // Refresh the table
|
||||
fetchCodes()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to create signup code')
|
||||
} finally {
|
||||
|
@ -116,7 +114,6 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
|||
<thead>
|
||||
<tr>
|
||||
<th className="text-left">Code</th>
|
||||
<th className="text-left">Email</th>
|
||||
<th className="text-left">Redeemed By</th>
|
||||
<th className="text-left">Expires On</th>
|
||||
</tr>
|
||||
|
@ -134,7 +131,6 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
|||
{code.code}
|
||||
</button>
|
||||
</td>
|
||||
<td>{code.email}</td>
|
||||
<td>{code.redeemedBy || 'Not redeemed'}</td>
|
||||
<td>{formatDate(code.expiresOn)}</td>
|
||||
</tr>
|
||||
|
@ -191,19 +187,6 @@ export default function SignupCodesManagementPage({ authService }: SignupCodesMa
|
|||
/>
|
||||
</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">
|
||||
<Button type="button" onClick={closeDialog} secondary>
|
||||
Cancel
|
||||
|
|
|
@ -19,7 +19,12 @@ export class AuthService {
|
|||
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', {
|
||||
body: { username, password, signupCode, email: null, rememberMe },
|
||||
credentials: 'include',
|
||||
|
@ -39,9 +44,9 @@ export class AuthService {
|
|||
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', {
|
||||
body: { code, email, name },
|
||||
body: { code, name },
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue