fix switch department not change country

This commit is contained in:
pakintada@gmail.com 2024-02-08 16:40:06 +07:00
parent d9a7961806
commit adefe31090
6 changed files with 152 additions and 92 deletions

View file

@ -3,6 +3,9 @@ import { CommonModule, NgOptimizedImage } from '@angular/common';
import { Router } from '@angular/router';
import { UserService } from '../services/user.service';
import { UserPermissions } from '../auth/userPermissions';
import { NotFoundHandler } from 'src/app/shared/helpers/notFoundHandler';
import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage';
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
@Component({
standalone: true,
@ -80,6 +83,9 @@ export class DepartmentComponent {
},
];
//
notfoundHandler = new NotFoundHandler();
constructor(
private router: Router,
private _userService: UserService
@ -108,6 +114,19 @@ export class DepartmentComponent {
}
onClick(id: string) {
// TODO: add handler for redirect
this.notfoundHandler.handleSwitchCountry(id, async () => {
// set country
await AsyncStorage.setItem('currentRecipeCountry', getCountryMapSwitcher(id));
// set filename, don't know which file was a target so use default
await AsyncStorage.setItem('currentRecipeFile', 'default');
}, async () => {
// set country to `tha`
await AsyncStorage.setItem('currentRecipeCountry', 'Thailand');
// set filename, don't know which file was a target so use default
await AsyncStorage.setItem('currentRecipeFile', 'default');
// safely return to recipes
});
void this.router.navigate([`/${id}/recipes`]);
}
}