Skip to content

Commit

Permalink
feat: update SubmitButton to accept custom text and improve error han…
Browse files Browse the repository at this point in the history
…dling in useAuth hook
  • Loading branch information
LeonardoMeireles55 committed Jan 17, 2025
1 parent 7577252 commit c690d23
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/auth/common/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ interface SubmitButtonProps {
text?: string;
}

const SubmitButton = ({ text = 'Entrar' }: SubmitButtonProps) => {
const SubmitButton = ({ text }: SubmitButtonProps) => {
return (
<button
type='submit'
Expand Down
5 changes: 4 additions & 1 deletion src/components/auth/hooks/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AuthFormData } from '@/components/auth/types/Auth';
import getStatusMessage from '@/components/utils/helpers/getStatusMessage';
import { authService } from '@/services/auth';
import { useRouter } from 'next/router';
import { useState } from 'react';
Expand Down Expand Up @@ -81,7 +82,9 @@ export const useAuth = (isLogin: boolean) => {
await authService.setSession(response.tokenJWT);
router.push('/hematology');
} else {
throw new Error(response.message || (isLogin ? 'Login failed' : 'Error creating account'));
throw new Error(
getStatusMessage(response.status) ?? 'An error occurred. Please try again later.'
);
}
} catch (err) {
console.error('Auth error:', err);
Expand Down
2 changes: 1 addition & 1 deletion src/components/auth/sign-in/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const LoginForm = () => {
</Link>
</div>

<SubmitButton />
<SubmitButton text='Sign-in' />

<p className='mt-6 text-center text-sm text-textSecondary'>
Don&apos;t have an account?{' '}
Expand Down

0 comments on commit c690d23

Please sign in to comment.