-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INFO (serif) : Shared Data Layer added. INFO (serif) : Redux and RTKQ…
…uery integration must be added on next article.
- Loading branch information
1 parent
5ac9ee6
commit 83898b1
Showing
84 changed files
with
4,030 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NX_BASE_PLATZI_STORE_SERVICE_URL=https://api.escuelajs.co/api/v1 | ||
NX_ACCESS_TOKEN_KEY=accessToken | ||
NX_REFRESH_TOKEN_KEY=refreshToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NX_BASE_PLATZI_STORE_SERVICE_URL=https://api.escuelajs.co/api/v1 | ||
NX_ACCESS_TOKEN_KEY=accessToken | ||
NX_REFRESH_TOKEN_KEY=refreshToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NX_BASE_PLATZI_STORE_SERVICE_URL=https://api.escuelajs.co/api/v1 | ||
NX_ACCESS_TOKEN_KEY=accessToken | ||
NX_REFRESH_TOKEN_KEY=refreshToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { | ||
LoginRequest, | ||
loginRequestSchema, | ||
paths, | ||
usePlatziStoreAuth, | ||
} from '@mfe-tutorial/data'; | ||
import { useToast } from '@mfe-tutorial/ui'; | ||
import { useForm } from 'react-hook-form'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export default function useLogin() { | ||
const navigate = useNavigate(); | ||
const { toast } = useToast(); | ||
const { error, handleLogin, loading, onResetError } = usePlatziStoreAuth(); | ||
|
||
const loginForm = useForm<LoginRequest>({ | ||
defaultValues: { | ||
email: 'john@mail.com', | ||
password: 'changeme', | ||
}, | ||
resolver: zodResolver(loginRequestSchema), | ||
}); | ||
|
||
async function onSubmit(data: LoginRequest) { | ||
const result = await handleLogin(data); | ||
|
||
toast({ | ||
title: result.title, | ||
description: result.message, | ||
variant: result.success ? 'default' : 'destructive', | ||
}); | ||
|
||
if (result.success) { | ||
navigate(paths.info); | ||
} | ||
} | ||
|
||
return { | ||
loginForm, | ||
loading: | ||
loading || | ||
loginForm.formState.isLoading || | ||
loginForm.formState.isSubmitting, | ||
error, | ||
onSubmit, | ||
onResetError, | ||
}; | ||
} |
Oops, something went wrong.