Skip to content

Commit

Permalink
feat: react to current language changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Nov 9, 2023
1 parent ef3245a commit 21bd57a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions app/src/app/pages/profile/profile.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ion-item>
<ion-label>{{ 'SETTINGS.LANGUAGE' | translate }}</ion-label>
<ion-select
value="{{ currentLanguage$ | async }}"
placeholder="{{ 'SETTINGS.SELECT' | translate }}"
(ionChange)="changeLanguage($event)"
>
Expand Down
6 changes: 6 additions & 0 deletions app/src/app/pages/profile/profile.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { UserCreated } from 'src/app/schemas/user/user';
import { Store } from '@ngrx/store';
import { AppState } from '../../state/app.state';
import { changeLanguageRequest } from '../../state/language/language.actions';
import {
getCurrentLanguage,
selectLanguage,
} from '../../state/language/language.selectors';

@Component({
selector: 'app-profile',
Expand All @@ -16,6 +20,8 @@ export class ProfilePage implements OnInit {
user?: UserCreated;
avatarNumber: number = 1;

currentLanguage$ = this.store.select(getCurrentLanguage);

constructor(
private authService: AuthService,
private http: HttpClient,
Expand Down
25 changes: 14 additions & 11 deletions app/src/app/state/auth/auth.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ export const selectAuth = (state: AppState) => state.auth;

export const getLoginFormErrorMessages = createSelector(selectAuth, (auth) => {
return match(auth.loginFormError)
.with(UserFormErrors.USER_NOT_FOUND, () => 'STRING_OF_USER_NOT_FOUND')
.with(
UserFormErrors.USER_NOT_FOUND,
() => 'LOGIN.USERNAME.ERROR_DOESNT_EXIST',
)
.with(
UserFormErrors.INCORRECT_PASSWORD,
() => 'STRING_OF_INCORRECT_PASSWORD',
() => 'LOGIN.PASSWORD.ERROR_INCORRECT_PASSWORD',
)
.with(
CredentialsError.INCORRECT_PHONE_NUMBER,
() => 'STRING_OF_INVALID_PHONE_NUMBER',
() => 'LOGIN.USERNAME.ERROR_FORMATTED',
)
.with(undefined, () => null)
.exhaustive();
});

// export const getLoginDeviceErrors = createSelector(selectAuth, (auth) => {
// if (auth.deviceError) return auth.deviceError;
// return null;
// });
//
// export const isAuthenticated = createSelector(selectAuth, (auth) => {
// return auth.isAuthenticated;
// });
export const getLoginDeviceErrors = createSelector(selectAuth, (auth) => {
if (auth.deviceError) return auth.deviceError;
return null;
});

export const isAuthenticated = createSelector(selectAuth, (auth) => {
return auth.isAuthenticated;
});

export const getCurrentCredentials = createSelector(selectAuth, (auth) => {
if (auth.userCredentials) {
Expand Down
20 changes: 19 additions & 1 deletion app/src/app/state/create-user/create-user.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { createSelector } from '@ngrx/store';
import { AppState } from '../app.state';
import { match } from 'ts-pattern';
import { UserFormError } from '../../schemas/user/validate/form';

export const selectCreateUser = (state: AppState) => state.createUser;

export const getCreateUserFormErrors = createSelector(
selectCreateUser,
(createUser) => {
if (createUser.error) return createUser.error;
if (createUser.error)
return match(createUser.error)
.with('PHONE_ALREADY_EXISTS', () => 'SIGNUP.ALREADY_EXISTING_USER')
.with({ type: 'INVALID_USER_DATA' }, (value) => value.message)
.with(
UserFormError.PASSWORDS_DO_NOT_MATCH,
() => 'SIGNUP.PASSWORDS_DONT_MATCH',
)
.with(
UserFormError.INCORRECT_PHONE_NUMBER,
() => 'SIGNUP.PHONE_NUMBER.INCORRECT_PHONE_NUMBER',
)
.with(
UserFormError.INCORRECT_EMERGENCY_NUMBER,
() => 'SIGNUP.EMERGENCY_NUMBER.INCORRECT_PHONE_NUMBER',
)
.exhaustive();
return null;
},
);
Expand Down
4 changes: 2 additions & 2 deletions app/src/app/state/loading/loading.selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export const isLoading = createSelector(
selectCreateUser,
(auth, create) => {
if (auth.isLoading)
return { isLoading: true, keyMessage: 'LOADING_AUTH' } as LoadingState;
return { isLoading: true, keyMessage: 'LOGIN.LOADING' } as LoadingState;
if (create.isLoading)
return {
isLoading: true,
keyMessage: 'LOADING_CREATE_USER',
keyMessage: 'SIGNUP.LOADING',
} as LoadingState;
return { isLoading: false } as LoadingState;
},
Expand Down
12 changes: 6 additions & 6 deletions app/src/app/state/menu/menu.selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export const getTopItems = createSelector(
if (auth.isAuthenticated) {
return [
{
titleTranslateKey: 'Home',
titleTranslateKey: 'MENU.HOME',
url: '/home',
icon: 'home',
},
{
titleTranslateKey: 'Reservations',
titleTranslateKey: 'MENU.RESERVATIONS',
url: '/reservations',
icon: 'folder',
},
] as MenuItem[];
}
return [
{
titleTranslateKey: 'Home',
titleTranslateKey: 'MENU.HOME',
url: '/home',
icon: 'home',
},
Expand All @@ -40,19 +40,19 @@ export const getBottomItems = createSelector(selectAuth, (auth) => {
if (auth.isAuthenticated)
return [
{
titleTranslateKey: 'Profile',
titleTranslateKey: 'MENU.PROFILE',
url: '/profile',
icon: 'person',
},
{
titleTranslateKey: 'Logout',
titleTranslateKey: 'MENU.LOGOUT',
url: '/logout',
icon: 'log-out',
},
] as MenuItem[];
return [
{
titleTranslateKey: 'Login',
titleTranslateKey: 'MENU.LOGIN',
url: '/login',
icon: 'log-in',
},
Expand Down

0 comments on commit 21bd57a

Please sign in to comment.