VictorSalome / Teste-Front-Taqtile

https://teste-front-taqtile.vercel.app
0 stars 0 forks source link

[Track 4/8] [INT] Login #7

Open taki-tiler[bot] opened 4 months ago

taki-tiler[bot] commented 4 months ago

Step 1/5 - Network Communication

Estimated time: 15 minutes

REST

Network communication is a crucial part of any system nowadays. Here in Taqtile we use a framework called GraphQL, which you'll use thoughout this onboard.

But for now, in order to you understand what's happening under the GraphQL's hood, let's start with the (not so) old fashion way of doing network requests: The Representational State Transfer a.k.a. REST.

For this, we'll just make a REST request using a tool called Postman. It should be installed in your mac already (download here if it doesn't). You will perform a Login request very similiar to the one you coding in the next steps. Here are the parameters of your request:

{
    "email": "admin@taqtile.com.br",
    "password": "1234qwer"
}

Note 1: There's no code in this step! It's just a warming up for you to have some knowledge of what's going on inside the GraphQL. Be patient, young padawan. The code will come (in the next steps btw).

If your request succeed, you'll receive on body a JSON that looks like this:

{
    "data": {
        "user": {
            "id": 51,
            "active": true,
            "email": "admin@taqtile.com.br",
            "createdAt": "2018-06-25T23:11:56.472Z",
            "updatedAt": "2019-01-17T15:28:04.567Z",
            "name": "Taqtile Adm",
            "role": "admin"
        },

    }
}

Note 2: The Postman is just a suggestion. Feel free to use any other tool to make a REST request.

VictorSalome commented 4 months ago

finish

taki-tiler[bot] commented 4 months ago

Step 2/5 - GraphQL

Estimated time: 2 hours

Getting started

As we got our feet wet with REST, let's get started with GraphQL.

A little bit of context: GraphQL is a framework created by Facebook πŸ™€ that makes easier for create flexible and extensible server aplications.

GraphQL can be a little scary at the first sight, but don't worry, you'll get used to it. Here are some tutorials to help you to get started with GraphQL:

Practice

As we do with REST, let's make a GraphQL request using a tool called GraphiQL (no code yet, hang in there). You should download Graphiql app because it helps a lot to set headers on requests, or another app thar does the same, like GraphQL Playground. Once done, access https://template-onboarding-node-sjz6wnaoia-uc.a.run.app/graphql and you're good to go.

In GraphiQL, you'll have to make the login mutation. Fortunally, the GraphiQL contains the documentation explorer (tab on right) which shows how the queries and mutations should be used.

The test user for this login mutation is:

Email: admin@taqtile.com.br
Password: 1234qwer
VictorSalome commented 4 months ago

finish

taki-tiler[bot] commented 4 months ago

Step 3/5 - Integrate the app with the server

Estimated time: 4 hours

In the previous step you made a GraphQL query using the GraphiQL tool, right? For this step, we'll make the same query in your project (code time πŸŽ‰).

In order to make GraphQL requests, we suggest the Apollo Client.

Once the library is installed, your job is to do the login mutation when the user presses the login button (which makes sense πŸ€”).

Login screen behaviour

When you finish this step, your login screen should have the following behaviour:

On Login Success

If everything goes well with the login mutation, you should store the received token, which will be used in your latter GraphQL requests. When storing the token you can use any method you want to save this data, but remember that it should persist even if the user quits the application.

On Login Error

If you get an error with the login mutation, just show the error message you'll receive from server.

The error response you'll receive in this case will have in its structure:

{
    "data": null,
    "errors": [
        {
            "name": "a string",
            "code": 500,
            "message": "a string"
        }
    ]
}
VictorSalome commented 4 months ago

finish

taki-tiler[bot] commented 4 months ago

Step 4/5: Navigation

Estimated time: 2 hours

Now we're working with a core part of our application: the navigation. After your login is successfull and your have stored the authentication token, it's time to navigate to the next page. We have some libs that makes our work easier. You can use any lib you want, but here are the ones we use on our projects:

React

React native

Follow the instructions to install and use it successfully. You can, for now, navigate to a blank page. It will be populated on your next track.

VictorSalome commented 4 months ago

finish

taki-tiler[bot] commented 4 months ago

Step 5/5: Challenge: Loading indicator

Estimated time: 2 hours

In order to give some feedback of what's going on inside your app, the challenge is to show a loading indicator, inside the login page, while the GraphQL request is being made.

Here are some SUGGESTIONS (don't mind about styling for now) of loading indicator:

Button Load (with change of text)

Button Loading

Page loading

Page Loading

NOTE: while on load, the user should not be able to click on the button again. This way we avoid performing the login request more times unecessarily.

VictorSalome commented 4 months ago

finish

taki-tiler[bot] commented 4 months ago

Click here for your next track