diff --git a/package.json b/package.json index 3ccbf5e7a..a880544cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@topcoder-platform/platform-ui", - "version": "2.6", + "version": "2.0.7", "private": true, "scripts": { "dev": "yarn react-app-rewired start", diff --git a/src-ts/lib/profile-provider/profile-functions/index.ts b/src-ts/lib/profile-provider/profile-functions/index.ts index feefd3b99..6de4cee2c 100644 --- a/src-ts/lib/profile-provider/profile-functions/index.ts +++ b/src-ts/lib/profile-provider/profile-functions/index.ts @@ -1,5 +1,6 @@ export { UserRole } from './profile-factory' export { - getAsync as profileGetAsync, + getLoggedInAsync as profileGetLoggedInAsync, + getPublicAsync as profileGetPublicAsync, editNameAsync as profileEditNameAsync, } from './profile.functions' diff --git a/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts b/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts index 13fe53fdd..34879354d 100644 --- a/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts +++ b/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts @@ -3,7 +3,7 @@ import { UserProfile } from '../../user-profile.model' import { UserRole } from './user-role.enum' -export function create(profile: UserProfile, token: TokenModel, hasDiceEnabled: boolean): UserProfile { +export function create(profile: UserProfile, token?: TokenModel, hasDiceEnabled?: boolean): UserProfile { // Currently, the "Self-Service Customer" role is being set when a user is created // during the self-service workflow. There are no other roles being set to distinguish @@ -12,14 +12,14 @@ export function create(profile: UserProfile, token: TokenModel, hasDiceEnabled: // This is imperfect, bc a user could be both a Customer or a Member, but for now // we are okay with this and will have a more in-depth initiave to properly assign // roles. - profile.isCustomer = !!token.roles?.some(role => role === UserRole.customer) + profile.isCustomer = !!token?.roles?.some(role => role === UserRole.customer) profile.isMember = !profile.isCustomer - profile.isWipro = profile.email.endsWith('@wipro.com') - profile.diceEnabled = hasDiceEnabled + profile.isWipro = profile.email?.endsWith('@wipro.com') + profile.diceEnabled = !!hasDiceEnabled // store roles for custom capability checks - profile.roles = token.roles || [] + profile.roles = token?.roles || [] // TODO: create the profile full name property return profile diff --git a/src-ts/lib/profile-provider/profile-functions/profile.functions.ts b/src-ts/lib/profile-provider/profile-functions/profile.functions.ts index ede0f9ef7..bdb5c8fc9 100644 --- a/src-ts/lib/profile-provider/profile-functions/profile.functions.ts +++ b/src-ts/lib/profile-provider/profile-functions/profile.functions.ts @@ -6,7 +6,7 @@ import { UserProfile } from '../user-profile.model' import { profileFactoryCreate } from './profile-factory' import { profileStoreGet, profileStorePatchName } from './profile-store' -export async function getAsync(handle?: string): Promise { +export async function getLoggedInAsync(handle?: string): Promise { // get the token const token: TokenModel = await tokenGetAsync() @@ -28,6 +28,15 @@ export async function getAsync(handle?: string): Promise { + + // get the profile + const profileResult: UserProfile = await profileStoreGet(handle) + + const output: UserProfile = profileFactoryCreate(profileResult) + return output +} + export async function editNameAsync(handle: string, profile: EditNameRequest): Promise { return profileStorePatchName(handle, profile) } diff --git a/src-ts/lib/profile-provider/profile.provider.tsx b/src-ts/lib/profile-provider/profile.provider.tsx index 7447e04f3..d646378a2 100644 --- a/src-ts/lib/profile-provider/profile.provider.tsx +++ b/src-ts/lib/profile-provider/profile.provider.tsx @@ -5,7 +5,7 @@ import { userUpdatePasswordAsync } from '../functions' import { ChangePasswordRequest } from './change-password-request.model' import { EditNameRequest } from './edit-name-request.model' import { ProfileContextData } from './profile-context-data.model' -import { profileEditNameAsync, profileGetAsync } from './profile-functions' +import { profileEditNameAsync, profileGetLoggedInAsync } from './profile-functions' import { UserProfile } from './user-profile.model' import profileContext, { defaultProfileContextData } from './profile.context' @@ -20,7 +20,7 @@ export const ProfileProvider: FC<{ children: ReactNode }> = ({ children }: { chi } async function getAndSetProfileAsync(): Promise { - const profile: UserProfile | undefined = await profileGetAsync() + const profile: UserProfile | undefined = await profileGetLoggedInAsync() const contextData: ProfileContextData = { changePassword, initialized: true, diff --git a/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx b/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx index 0d6dd0a0d..6be68de30 100644 --- a/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx +++ b/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx @@ -3,7 +3,7 @@ import { Params, useParams, useSearchParams } from 'react-router-dom' import { LoadingSpinner, - profileGetAsync, + profileGetPublicAsync, UserProfile, } from '../../../../lib' import { getViewStyleParamKey } from '../../learn.routes' @@ -28,7 +28,7 @@ const UserCertificate: FC<{}> = () => { useEffect(() => { if (routeParams.memberHandle) { - profileGetAsync(routeParams.memberHandle) + profileGetPublicAsync(routeParams.memberHandle) .then(userProfile => { setProfile(userProfile) setProfileReady(true)