import { useState } from 'react'; import { errorMessage } from '../../api/client'; import { Button, Card, FormField, Input, useToast, } from '@cameleer/design-system'; import { useChangePassword } from '../../api/account-hooks'; import styles from '../../styles/platform.module.css'; export function PasswordChangeSection() { const { toast } = useToast(); const changePassword = useChangePassword(); const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); async function handleChangePassword(e: React.FormEvent) { e.preventDefault(); if (newPassword.length < 8) { toast({ title: 'Password must be at least 8 characters', variant: 'error' }); return; } if (newPassword !== confirmPassword) { toast({ title: 'Passwords do not match', variant: 'error' }); return; } try { await changePassword.mutateAsync({ currentPassword, newPassword }); toast({ title: 'Password changed successfully', variant: 'success' }); setCurrentPassword(''); setNewPassword(''); setConfirmPassword(''); } catch (err) { toast({ title: 'Failed to change password', description: errorMessage(err), variant: 'error' }); } } return (

Update your login password. Minimum 8 characters.

setCurrentPassword(e.target.value)} placeholder="Enter current password" required /> setNewPassword(e.target.value)} placeholder="Enter new password" required minLength={8} /> setConfirmPassword(e.target.value)} placeholder="Confirm new password" required minLength={8} />
); }