feat(aihr): align figma pages for release
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import type { OrgSnapshotResponse } from '@/types/api';
|
||||
import type { MobileIdentity, OrgSnapshotResponse, RoleKey } from '@/types/api';
|
||||
import { apiRequest } from './api';
|
||||
import {
|
||||
getAuth,
|
||||
hasSelectedPosition,
|
||||
normalizePosition,
|
||||
roleKey,
|
||||
saveSelectedPosition,
|
||||
type UserPosition
|
||||
} from './auth';
|
||||
@@ -17,6 +18,31 @@ export const userTabPages = new Set([
|
||||
|
||||
export const isUserRoute = (url: string) => url.startsWith('/pages/user/');
|
||||
|
||||
export const isSupervisorRoute = (url: string) => url.startsWith('/pages/supervisor/');
|
||||
|
||||
export const routeForMobileRole = (role: RoleKey, requested: string) => {
|
||||
if (role === 'supervisor' && (isUserRoute(requested) || isSupervisorRoute(requested))) {
|
||||
return '/pages/supervisor/index/index';
|
||||
}
|
||||
return requested;
|
||||
};
|
||||
|
||||
export const hydrateMobileRole = async (): Promise<RoleKey> => {
|
||||
try {
|
||||
const identity = await apiRequest<MobileIdentity>({
|
||||
url: '/api/aihr/mobile/me',
|
||||
method: 'GET',
|
||||
timeout: 15000,
|
||||
clearAuthOnUnauthorized: false
|
||||
});
|
||||
const role = identity.role === 'supervisor' ? 'supervisor' : 'user';
|
||||
uni.setStorageSync(roleKey, role);
|
||||
return role;
|
||||
} catch {
|
||||
return (uni.getStorageSync(roleKey) === 'supervisor' ? 'supervisor' : 'user') as RoleKey;
|
||||
}
|
||||
};
|
||||
|
||||
export const positionSetupUrl = (redirect: string) =>
|
||||
`/pages/auth/position/index?redirect=${encodeURIComponent(redirect || '/pages/user/today/index')}`;
|
||||
|
||||
@@ -46,6 +72,9 @@ export const hydratePositionFromOrg = async (phone = getAuth().phone): Promise<U
|
||||
};
|
||||
|
||||
export const nextUserRouteAfterLogin = async (redirect: string) => {
|
||||
const role = await hydrateMobileRole();
|
||||
const roleRoute = routeForMobileRole(role, redirect);
|
||||
if (roleRoute !== redirect) return roleRoute;
|
||||
if (!isUserRoute(redirect) || hasSelectedPosition()) return redirect;
|
||||
const officialPosition = await hydratePositionFromOrg();
|
||||
return normalizePosition(officialPosition) ? redirect : positionSetupUrl(redirect);
|
||||
|
||||
Reference in New Issue
Block a user