Skip to content

Commit 2452354

Browse files
author
Rajat Saxena
committed
Existing membership screen during checkout; queue jobs with local fallbacks
1 parent 974f77a commit 2452354

File tree

17 files changed

+413
-299
lines changed

17 files changed

+413
-299
lines changed

apps/web/components/community/create-post-dialog.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState, useEffect } from "react";
3+
import { useState, useEffect, useContext } from "react";
44
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
55
import { Button } from "@/components/ui/button";
66
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
@@ -24,6 +24,7 @@ import { GifSelector } from "./gif-selector";
2424
import { MediaPreview } from "./media-preview";
2525
import { CommunityPost } from "@courselit/common-models";
2626
import { type MediaItem } from "./media-item";
27+
import { ProfileContext } from "@components/contexts";
2728

2829
interface CreatePostDialogProps {
2930
onPostCreated: (
@@ -51,6 +52,7 @@ export function CreatePostDialog({
5152
category?: string;
5253
}>({});
5354
const [isPostButtonDisabled, setIsPostButtonDisabled] = useState(true);
55+
const { profile } = useContext(ProfileContext);
5456

5557
useEffect(() => {
5658
setIsPostButtonDisabled(title.trim() === "" || content.trim() === "");
@@ -172,13 +174,22 @@ export function CreatePostDialog({
172174
<div className="flex items-center gap-2 mb-4">
173175
<Avatar className="h-10 w-10">
174176
<AvatarImage
175-
src="/courselit_backdrop_square.webp"
176-
alt="Your avatar"
177+
src={
178+
profile.avatar
179+
? profile.avatar.file
180+
: "/courselit_backdrop_square.webp"
181+
}
182+
alt={`${profile.name} avatar`}
177183
/>
178-
<AvatarFallback>YN</AvatarFallback>
184+
<AvatarFallback>
185+
{(profile.name
186+
? profile.name.charAt(0)
187+
: profile.email.charAt(0)
188+
).toUpperCase()}
189+
</AvatarFallback>
179190
</Avatar>
180191
<div>
181-
<span className="font-semibold">Your Name</span>
192+
<span className="font-semibold">{profile.name}</span>
182193
</div>
183194
</div>
184195

apps/web/components/community/info.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function CommunityInfo({
9494
navigator.clipboard.writeText(`${address.frontend}/p/${pageId}`);
9595
toast({
9696
title: TOAST_TITLE_SUCCESS,
97-
description: "Page ID copied to clipboard!",
97+
description: "Page URL copied to clipboard!",
9898
});
9999
};
100100

apps/web/components/community/membership-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function MembershipList({ id }: { id: string }) {
100100

101101
const loadMembers = async () => {
102102
const query = `
103-
query ($communityId: String!, $page: Int, $limit: Int, $status: MemberStatus) {
103+
query ($communityId: String!, $page: Int, $limit: Int, $status: MembershipStatusType) {
104104
members: getMembers(communityId: $communityId, page: $page, limit: $limit, status: $status) {
105105
user {
106106
userId

apps/web/components/public/payments/checkout.tsx

Lines changed: 226 additions & 137 deletions
Large diffs are not rendered by default.

apps/web/graphql/communities/query.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
CommunityMemberStatus,
2525
CommunityReportStatus,
2626
} from "@courselit/common-models";
27+
import userTypes from "../users/types";
2728

2829
const queries = {
2930
getCommunity: {
@@ -65,7 +66,7 @@ const queries = {
6566
type: new GraphQLNonNull(GraphQLString),
6667
},
6768
status: {
68-
type: types.memberStatusType,
69+
type: userTypes.membershipStatusType,
6970
},
7071
},
7172
resolve: async (
@@ -96,7 +97,7 @@ const queries = {
9697
type: new GraphQLNonNull(GraphQLString),
9798
},
9899
status: {
99-
type: types.memberStatusType,
100+
type: userTypes.membershipStatusType,
100101
},
101102
},
102103
resolve: (

apps/web/graphql/communities/types.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ import { getUser } from "../users/logic";
1616
import GQLContext from "@models/GQLContext";
1717
import paymentPlansTypes from "../paymentplans/types";
1818

19-
const memberStatusMap = {};
20-
for (const status of [
21-
Constants.MembershipStatus.PENDING,
22-
Constants.MembershipStatus.ACTIVE,
23-
Constants.MembershipStatus.REJECTED,
24-
]) {
25-
memberStatusMap[status.toUpperCase()] = { value: status };
26-
}
27-
28-
const memberStatusType = new GraphQLEnumType({
29-
name: "MemberStatus",
30-
values: memberStatusMap,
31-
});
32-
3319
const communityReportContentType = new GraphQLEnumType({
3420
name: "CommunityReportContentType",
3521
values: Object.fromEntries(
@@ -121,7 +107,7 @@ const communityMemberStatus = new GraphQLObjectType({
121107
resolve: (member, _, ctx: GQLContext, __) =>
122108
getUser(member.userId, ctx),
123109
},
124-
status: { type: memberStatusType },
110+
status: { type: userTypes.membershipStatusType },
125111
joiningReason: { type: GraphQLString },
126112
rejectionReason: { type: GraphQLString },
127113
},
@@ -201,7 +187,6 @@ const types = {
201187
community,
202188
communityPost,
203189
communityMemberStatus,
204-
memberStatusType,
205190
communityPostInputMedia,
206191
communityComment,
207192
communityReportContentType,

apps/web/graphql/mails/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import SearchData from "./models/search-data";
66
import DownloadLinkModel from "@models/DownloadLink";
77
import pug from "pug";
88
import digitalDownloadTemplate from "../../templates/download-link";
9-
import { send } from "../../services/mail";
109
import { responses } from "@config/strings";
1110
import { generateEmailFrom } from "@/lib/utils";
11+
import { addMailJob } from "@/services/queue";
1212

1313
export function areAllEmailIdsValid(
1414
emailsOrder: string[],
@@ -92,7 +92,7 @@ export async function createTemplateAndSendMail({
9292
hideCourseLitBranding: ctx.subdomain.settings?.hideCourseLitBranding,
9393
});
9494

95-
await send({
95+
await addMailJob({
9696
to: [user.email],
9797
subject: `Thank you for signing up for ${course.title}`,
9898
body: emailBody,

apps/web/graphql/mails/logic.ts

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -708,113 +708,6 @@ export async function getMailsCount(
708708
return await MailModel.countDocuments(query);
709709
}
710710

711-
// export async function updateMail(
712-
// mailData: Pick<Mail, "mailId" | "to" | "subject" | "body"> = {},
713-
// ctx: GQLContext,
714-
// ): Promise<Mail | null> {
715-
// checkIfAuthenticated(ctx);
716-
717-
// let mail: Mail | null = await MailModel.findOne({
718-
// mailId: mailData.mailId,
719-
// domain: ctx.subdomain._id,
720-
// });
721-
722-
// if (!isNotUndefined(mail)) {
723-
// throw new Error(responses.item_not_found);
724-
// }
725-
726-
// if (!checkPermission(ctx.user.permissions, [permissions.manageUsers])) {
727-
// throw new Error(responses.action_not_allowed);
728-
// }
729-
730-
// if (
731-
// mailData.subject &&
732-
// mailData.subject.length > UIConstants.MAIL_SUBJECT_MAX_LENGTH
733-
// ) {
734-
// throw new Error(responses.mail_subject_length_exceeded);
735-
// }
736-
737-
// if (mailData.to) {
738-
// mailData.to = removeEmptyMembers(Array.from(new Set(mailData.to)));
739-
// }
740-
741-
// if (mailData.to && mailData.to.length > UIConstants.MAIL_MAX_RECIPIENTS) {
742-
// throw new Error(responses.mail_max_recipients_exceeded);
743-
// }
744-
745-
// try {
746-
// for (const key of Object.keys(mailData)) {
747-
// if (key === "mailId") continue;
748-
749-
// mail[key] = mailData[key];
750-
// }
751-
752-
// mail = await (mail as any).save();
753-
754-
// return mail;
755-
// } catch (e: any) {
756-
// error(e.message, {
757-
// stack: e.stack,
758-
// });
759-
// return null;
760-
// }
761-
// }
762-
763-
// const removeEmptyMembers = (arr: string[]) =>
764-
// arr.filter((x) => x.trim() !== "");
765-
766-
// function isNotUndefined(mail: Mail | null): mail is Mail {
767-
// return !!mail;
768-
// }
769-
770-
// export async function sendMail(mailId: string, ctx: GQLContext): Promise<Mail> {
771-
// checkIfAuthenticated(ctx);
772-
773-
// let mail: Mail | null = await MailModel.findOne({
774-
// mailId: mailId,
775-
// domain: ctx.subdomain._id,
776-
// });
777-
778-
// if (!isNotUndefined(mail)) {
779-
// throw new Error(responses.item_not_found);
780-
// }
781-
782-
// if (!checkPermission(ctx.user.permissions, [permissions.manageUsers])) {
783-
// throw new Error(responses.action_not_allowed);
784-
// }
785-
786-
// if (mail.published) {
787-
// throw new Error(responses.mail_already_sent);
788-
// }
789-
790-
// if (!mail.to || !mail.subject || !mail.body) {
791-
// throw new Error(responses.invalid_mail);
792-
// }
793-
794-
// const from = `${ctx.subdomain.settings.title || ctx.subdomain.name} ${
795-
// ctx.user.email
796-
// }`;
797-
798-
// await send({
799-
// from,
800-
// to: mail.to,
801-
// subject: mail.subject,
802-
// body: mail.body,
803-
// });
804-
805-
// mail.published = true;
806-
// try {
807-
// await (mail as any).save();
808-
809-
// return mail;
810-
// } catch (e: any) {
811-
// error(e.message, {
812-
// stack: e.stack,
813-
// });
814-
// throw new Error(responses.internal_error);
815-
// }
816-
// }
817-
818711
export async function sendCourseOverMail(
819712
courseId: string,
820713
email: string,

apps/web/graphql/paymentplans/mutation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { GraphQLInt, GraphQLNonNull, GraphQLString } from "graphql";
22
import types from "./types";
33
import { archivePaymentPlan, changeDefaultPlan, createPlan } from "./logic";
44
import { MembershipEntityType } from "@courselit/common-models";
5+
import userTypes from "../users/types";
56

67
const mutations = {
78
createPlan: {
@@ -11,7 +12,7 @@ const mutations = {
1112
type: { type: new GraphQLNonNull(types.paymentPlanType) },
1213
entityId: { type: new GraphQLNonNull(GraphQLString) },
1314
entityType: {
14-
type: new GraphQLNonNull(types.membershipEntityType),
15+
type: new GraphQLNonNull(userTypes.membershipEntityType),
1516
},
1617
oneTimeAmount: { type: GraphQLInt },
1718
emiAmount: { type: GraphQLInt },
@@ -63,7 +64,7 @@ const mutations = {
6364
planId: { type: new GraphQLNonNull(GraphQLString) },
6465
entityId: { type: new GraphQLNonNull(GraphQLString) },
6566
entityType: {
66-
type: new GraphQLNonNull(types.membershipEntityType),
67+
type: new GraphQLNonNull(userTypes.membershipEntityType),
6768
},
6869
},
6970
resolve: async (
@@ -86,7 +87,7 @@ const mutations = {
8687
planId: { type: new GraphQLNonNull(GraphQLString) },
8788
entityId: { type: new GraphQLNonNull(GraphQLString) },
8889
entityType: {
89-
type: new GraphQLNonNull(types.membershipEntityType),
90+
type: new GraphQLNonNull(userTypes.membershipEntityType),
9091
},
9192
},
9293
resolve: async (

apps/web/graphql/paymentplans/types.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,7 @@ import {
66
GraphQLString,
77
} from "graphql";
88
import { Constants } from "@courselit/common-models";
9-
const { PaymentPlanType, MembershipEntityType } = Constants;
10-
11-
const membershipEntityType = new GraphQLEnumType({
12-
name: "MembershipEntityType",
13-
values: Object.fromEntries(
14-
Object.entries(MembershipEntityType).map(([key, value]) => [
15-
key,
16-
{ value: value },
17-
]),
18-
),
19-
});
9+
const { PaymentPlanType } = Constants;
2010

2111
const paymentPlanType = new GraphQLEnumType({
2212
name: "PaymentPlanType",
@@ -45,7 +35,6 @@ const paymentPlan = new GraphQLObjectType({
4535
const types = {
4636
paymentPlan,
4737
paymentPlanType,
48-
membershipEntityType,
4938
};
5039

5140
export default types;

0 commit comments

Comments
 (0)