// src/components/admin/AddClientForm.tsx
'use client';
import { useState } from 'react';
import { Button, TextField, DialogContent, DialogActions, Alert } from '@mui/material';
import api from '@/lib/axios';
interface Props {
onClose: () => void;
onClientCreated?: () => void;
}
export default function AddClientForm({ onClose, onClientCreated }: Props) {
const [clientName, setClientName] = useState('');
const [error, setError] = useState('');
const [success, setSuccess] = useState('');
const handleSubmit = async () => {
try {
const res = await api.post('/auth/register/client', { clientName });
setSuccess(`Client ID: ${res.data.clientId}, Identifier: ${res.data.clientIdentifier}`);
setClientName('');
setError('');
if (onClientCreated) onClientCreated();
onClose();
} catch (err: any) {
setError(err.response?.data?.message || 'Unexpected error');
setSuccess('');
}
};
return (
<>
setClientName(e.target.value)}
/>
{error && {error}}
{success && {success}}
>
);
}