hello everyone my name is paolo alvis and on this video we're going to start the state management of the logging screen for our real app using the ionic framework and ngrx we also create a service that soon will connect to our database and to our backend so subscribe to the channel in case you want to follow this development and let's take a look on what we are going to have built by the end of the video on this video we are going to work on the forgot email password functionality using redux we can see that in the beginning the stage is empty and nothing is happening if i put a valid email on the email field and i click on the forgot email password button the state changes so i'm recovering the password now i show the loading component and the service attribute responds with success so now the password is recovered and then i call the action to hide the loading component if i restart this flow and i put an error email in my email field and i click on the forgot email password button something similar happens with this date i try to recover the password and i show the loading component as the recover password fails i have an error message i hide the loading component and i show the error message so let's go to the code as our goal is to create the state management for the login page we can go to the app store folder and create a new folder for the login stage which will be called logging inside of this folder we'll create a new file called loginstate. ts that will represent the state of the login page here you can export an interface called loginstate so let's take a look at the login page and find out what states we need to manage here we need to know if the user is recovering the email password and also if the user managed to recover their email or password so let's create two properties on the login state one will be the property is recovering password which is a boolean and the other one will be the property is recovered password which is also a boolean also we need to know if the user is trying to log in and if the user managed to login so let's create two more properties for this is logging in which is a boolean and is logged in which is also a boolean we also need to know if there was an error on any of those moments so let's create an error property to manage that possibility and that's all we need for now to manage the state of our login page now that we have created the representation of the login page state let's set this representation to our other interface called app stage which actually represents our whole store now let's go to the next step and create the login page actions just to remind you actions are instructions we are going to send to the store to let the store know how it should update itself to do this i'll create a new file called login. actions.
ts this file will have all the actions of the logging state let's start with the actions that are involved on the email password recovery we'll export a constant called recover password that will receive the create action function of ngrx we'll identify this action by the string recover password and this action will receive no properties or no parameters to it that's our first action so let's think about of the flow of the login page the user will click on the forgot email password button and we'll dispatch the action to the store based on this action the login page will know the user is trying to recover its email password and will call a service to recover it if that service is successful then you have to update the state of the login page informing the login page that the user managed to recover its email password so this service will have to call a new action to update the store let's create then this new action to do this i will export a constant called recover password success that will receive the create action function of ngrx we will identify this action by the string recover password success and this action doesn't need to receive any properties as we are only interested in the success of the requests not on its response all right now we need to do something similar in case there was an error on the recovery of the email password when there is an error the service will have to go on action to update the store with that error so let's create this new action i'll export a constant called recover password fail that will receive the create action function of ngrx we'll identify this action by the string recover password fail and this action receives as property the error so this is how we declare that an action has properties all right now only the actions related to the logging are missing but let's first take care of the forgot email password part of the login page and then we'll come back to the login itself the next step is to create the reducers for the login page the reducers are responsible for receiving the action dispatched identifying them and returning to distort the new state let's create a new file called login. reducers. ts of it we create a constant called initial state which is of the type logging state and will be initialized with all its properties equal to no or false now we will create a constant called reducer that we receive the create reducer function of ndrx our reducer will receive the initial state we just defined and will have a list of actions that the reducer will be able to work on top of them so on the recover password action will execute a function that has as its parameter the current state and this function will return the new state for now let's just return the current state let's do something similar to the success and fail action so i'll just copy and paste and change the names of the actions now i'll export a function called loginreducer which receives a state of the type loginstate and an action this function returns the reducer that we just defined and passes to it the state and the action now let's set this login reducer to our store so the store knows it exists we go to the appstoremodule.
ts file and can add a new entry with the login reducer all right now our restore has the logging states let's now create some tests to manage the changes we make on top of those actions i'll create a file called login. store. spec.