Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/web/src/components/Settings/PersonalDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { useBlock } from "@litespace/ui/hooks/common";
type Form = {
name: string;
email: string;
price?: number;
phone: string;
city: IUser.City | null;
notice: number;
Expand Down Expand Up @@ -97,6 +98,7 @@ const PersonalDetails: React.FC<Props> = ({
const validators = useMakeValidators<Form>({
name: { required: !!name, validate: validateUserName },
email: { required: true, validate: validateEmail },
price: { required: true },
phone: { required: false, validate: validatePhone },
notice: { required: false, validate: validateNotice },
});
Expand Down Expand Up @@ -240,6 +242,20 @@ const PersonalDetails: React.FC<Props> = ({
disabled={!forStudent}
/>

{!forStudent ? (
<Input
id="price"
name="price"
value={form.state.email}
onChange={(e) => form.set("email", e.target.value)}
label={intl("labels.email")}
placeholder={intl("labels.email.placeholder")}
state={form.errors?.email ? "error" : undefined}
helper={form.errors?.email}
autoComplete="off"
/>
) : null}

<PatternInput
id="phone"
name="phone"
Expand Down
2 changes: 2 additions & 0 deletions packages/headless/src/tutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function useFindTutorActivityScore(id: number | null): {
type IForm = {
bio: string;
about: string;
price: number;
};

export function useIntroduceTutor({
Expand All @@ -149,6 +150,7 @@ export function useIntroduceTutor({
return await api.user.update(profile.id, {
bio: fields.bio,
about: fields.about,
price: fields.price,
});
},
[api.user, profile]
Expand Down
14 changes: 14 additions & 0 deletions packages/models/migrations/1761636171596_add-price-to-tutors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationBuilder } from "node-pg-migrate";

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.addColumn("tutors", {
price: {
type: "int",
notNull: false,
},
});
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.dropColumn("tutors", "price");
}
4 changes: 4 additions & 0 deletions packages/models/src/tutors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const fullTutorFields: FullTutorFieldsMap = {
thumbnail: tutorColumn("thumbnail"),
notice: tutorColumn("notice"),
activated: tutorColumn("activated"),
price: tutorColumn("price"),
bypass_onboarding: tutorColumn("bypass_onboarding"),
} as const;

Expand Down Expand Up @@ -85,6 +86,7 @@ export class Tutors {
.update({
bio: payload.bio,
about: payload.about,
price: payload.price,
video: payload.video,
notice: payload.notice,
thumbnail: payload.thumbnail,
Expand Down Expand Up @@ -507,6 +509,7 @@ export class Tutors {
id: row.id,
bio: row.bio,
about: row.about,
price: row.price,
video: row.video,
thumbnail: row.thumbnail,
studioId: row.studio_id,
Expand Down Expand Up @@ -543,6 +546,7 @@ export class Tutors {
id: row.id,
bio: row.bio,
about: row.about,
price: row.price,
video: row.video,
thumbnail: row.thumbnail,
studioId: row.studio_id,
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/tutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Self = {
id: number;
bio: string | null;
about: string | null;
price: number | null;
video: string | null;
studioId: number | null;
thumbnail: string | null;
Expand Down Expand Up @@ -74,6 +75,7 @@ export type Row = {
notice: number;
bio: string | null;
about: string | null;
price: number | null;
video: string | null;
role: IUser.Role;
activated: boolean;
Expand All @@ -95,6 +97,7 @@ export type TutorMedia = {
export type UpdatePayload = {
bio?: string | null;
about?: string | null;
price?: number | null;
video?: string | null;
thumbnail?: string | null;
studioId?: number | null;
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type UpdateApiPayload = {
video?: null;
bio?: string | null;
about?: string | null;
price?: number | null;
phone?: string | null;
city?: City | null;
studioId?: number | null;
Expand Down
11 changes: 8 additions & 3 deletions packages/utils/src/lesson.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { ILesson } from "@litespace/types";
import { ILesson, ITutor } from "@litespace/types";
import { MINUTES_IN_HOUR, TOTAL_LESSON_HOURLY_RATE } from "@/constants";
import { sumBy } from "lodash";

/**
* @param duration {ILesson.Duration}
* @returns scaled lesson price
*/
export function calculateLessonPrice(duration: ILesson.Duration): number {
return Math.floor((duration / MINUTES_IN_HOUR) * TOTAL_LESSON_HOURLY_RATE);
export function calculateLessonPrice(
duration: ILesson.Duration,
tutor?: ITutor.Self
): number {
return Math.floor(
(duration / MINUTES_IN_HOUR) * (tutor?.price ?? TOTAL_LESSON_HOURLY_RATE)
);
}

export function sumLessonsDuration(lessons: ILesson.Self[]): number {
Expand Down
2 changes: 2 additions & 0 deletions services/server/src/handlers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ function update(_: ApiContext) {
video,
bio,
about,
price,
notice,
studioId,
phone,
Expand Down Expand Up @@ -382,6 +383,7 @@ function update(_: ApiContext) {
const updateTutorPayload: ITutor.UpdatePayload = {
bio,
about,
price,
notice,
studioId,
video,
Expand Down
5 changes: 4 additions & 1 deletion services/server/src/lib/lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,13 @@ export async function createLesson({
slotId,
start,
duration,
price,
});
if (tutor instanceof Error) return tutor;

const price = isTutorManager(tutor) ? 0 : calculateLessonPrice(duration);
const price = isTutorManager(tutor)
? 0
: calculateLessonPrice(duration, tutor.price);

// Create the lesson with its associated room if it doesn't exist
const roomMembers = [userId, tutorId];
Expand Down
Loading