Files
developer-roadmap/src/api/user.ts
T
Kamran AhmedandArik Chakma ad6002a514 feat: profile pages, custom roadmap pages and SSR (#5494)
* Update

* Add stats and health endpoints

* Add pre-render

* fix: redirect to the error page

* Fix generate-renderer issue

* Rename

* Fix best practice topics not loading

* Handle SSR for static pages

* Refactor faqs

* Refactor best practices

* Fix absolute import

* Fix stats

* Add custom roadmap page

* Minor UI change

* feat: custom roadmap slug routes (#4987)

* feat: replace roadmap slug

* fix: remove roadmap slug

* feat: username route

* fix: user public page

* feat: show roadmap progress

* feat: update public profile

* fix: replace with toast

* feat: user public profile page

* feat: implement profile form

* feat: implement user profile roadmap page

* refactor: remove logs

* fix: increase progress gap

* fix: remove title margin

* fix: breakpoint for roadmaps

* Update dependencies

* Upgrade dependencies

* fix: improper avatars

* fix: heatmap focus

* wip: remove `getStaticPaths`

* fix: add disable props

* wip

* feat: add email icon

* fix: update pnpm lock

* fix: implement author page

* Fix beginner roadmaps not working

* Changes to form

* Refactor profile and form

* Refactor public profile form

* Rearrange sidebar items

* Update UI for public form

* Minor text update

* Refactor public profile form

* Error page for user

* Revamp UI for profile page

* Add public profile page

* Fix vite warnings

* Add private profile banner

* feat: on blur check username

* Update fetch depth

* Add error detail

* Use hybrid mode of rendering

* Do not pre-render stats pages

* Update deployment workflow

* Update deployment workflow

---------

Co-authored-by: Arik Chakma <arikchangma@gmail.com>
2024-04-11 22:35:52 +01:00

125 lines
3.1 KiB
TypeScript

import { type APIContext } from 'astro';
import { api } from './api.ts';
import type { ResourceType } from '../lib/resource-progress.ts';
export const allowedRoadmapVisibility = ['all', 'none', 'selected'] as const;
export type AllowedRoadmapVisibility =
(typeof allowedRoadmapVisibility)[number];
export const allowedCustomRoadmapVisibility = [
'all',
'none',
'selected',
] as const;
export type AllowedCustomRoadmapVisibility =
(typeof allowedCustomRoadmapVisibility)[number];
export const allowedProfileVisibility = ['public', 'private'] as const;
export type AllowedProfileVisibility =
(typeof allowedProfileVisibility)[number];
export interface UserDocument {
_id?: string;
name: string;
email: string;
avatar?: string;
password: string;
isEnabled: boolean;
authProvider: 'github' | 'google' | 'email' | 'linkedin';
metadata: Record<string, any>;
calculatedStats: {
activityCount: number;
totalVisitCount: number;
longestVisitStreak: number;
currentVisitStreak: number;
updatedAt: Date;
};
verificationCode: string;
resetPasswordCode: string;
isSyncedWithSendy: boolean;
links?: {
github?: string;
linkedin?: string;
twitter?: string;
website?: string;
};
username?: string;
profileVisibility: AllowedProfileVisibility;
publicConfig?: {
isAvailableForHire: boolean;
isEmailVisible: boolean;
headline: string;
roadmaps: string[];
customRoadmaps: string[];
roadmapVisibility: AllowedRoadmapVisibility;
customRoadmapVisibility: AllowedCustomRoadmapVisibility;
};
resetPasswordCodeAt: string;
verifiedAt: string;
createdAt: string;
updatedAt: string;
}
export type UserActivityCount = {
activityCount: Record<string, number>;
totalActivityCount: number;
};
type ProgressResponse = {
updatedAt: string;
title: string;
id: string;
learning: number;
skipped: number;
done: number;
total: number;
isCustomResource?: boolean;
roadmapSlug?: string;
};
export type GetPublicProfileResponse = Omit<
UserDocument,
'password' | 'verificationCode' | 'resetPasswordCode' | 'resetPasswordCodeAt'
> & {
activity: UserActivityCount;
roadmaps: ProgressResponse[];
isOwnProfile: boolean;
};
export type GetUserProfileRoadmapResponse = {
title: string;
topicCount: number;
roadmapSlug?: string;
isCustomResource?: boolean;
done: string[];
learning: string[];
skipped: string[];
nodes: any[];
edges: any[];
};
export function userApi(context: APIContext) {
return {
getPublicProfile: async function (username: string) {
return api(context).get<GetPublicProfileResponse>(
`${import.meta.env.PUBLIC_API_URL}/v1-get-public-profile/${username}`,
);
},
getUserProfileRoadmap: async function (
username: string,
resourceId: string,
resourceType: ResourceType = 'roadmap',
) {
return api(context).get<GetUserProfileRoadmapResponse>(
`${
import.meta.env.PUBLIC_API_URL
}/v1-get-user-profile-roadmap/${username}`,
{
resourceId,
resourceType,
},
);
},
};
}