Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TBCCT-22] Profile page #38

Merged
merged 6 commits into from
Oct 16, 2024
Merged
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
4 changes: 2 additions & 2 deletions api/src/modules/notifications/email/email.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { forwardRef, Module } from '@nestjs/common';
import { IEmailServiceToken } from '@api/modules/notifications/email/email-service.interface';
import { NodemailerEmailService } from '@api/modules/notifications/email/nodemailer.email.service';
import { AuthModule } from '@api/modules/auth/auth.module';
import { EmailFailedEventHandler } from '@api/modules/notifications/email/events/handlers/emai-failed-event.handler';
import { SendWelcomeEmailHandler } from '@api/modules/notifications/email/commands/handlers/send-welcome-email.handler';
import { SendEmailConfirmationHandler } from '@api/modules/notifications/email/commands/handlers/send-email-confirmation.handler';
import { EmailProviderFactory } from '@api/modules/notifications/email/email.provider';

@Module({
imports: [forwardRef(() => AuthModule)],
providers: [
{ provide: IEmailServiceToken, useClass: NodemailerEmailService },
EmailProviderFactory,
SendEmailConfirmationHandler,
SendWelcomeEmailHandler,
EmailFailedEventHandler,
Expand Down
17 changes: 17 additions & 0 deletions api/src/modules/notifications/email/email.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FactoryProvider } from '@nestjs/common';
import { IEmailServiceToken } from '@api/modules/notifications/email/email-service.interface';
import { MockEmailService } from '../../../../test/utils/mocks/mock-email.service';
import { NodemailerEmailService } from '@api/modules/notifications/email/nodemailer.email.service';
import { ApiConfigService } from '@api/modules/config/app-config.service';
import { EventBus } from '@nestjs/cqrs';

export const EmailProviderFactory: FactoryProvider = {
provide: IEmailServiceToken,
useFactory: (configService: ApiConfigService, eventBus: EventBus) => {
const env = configService.get('NODE_ENV');
return env === 'test'
? new MockEmailService()
: new NodemailerEmailService(eventBus, configService);
},
inject: [ApiConfigService],
};
2 changes: 1 addition & 1 deletion api/src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class UsersController {
async update(@GetUser() user: User): ControllerResponse {
return tsRestHandler(usersContract.updateMe, async ({ body }) => {
const updatedUser = await this.usersService.update(user.id, body);
return { body: { data: updatedUser }, status: HttpStatus.CREATED };
return { body: { data: updatedUser }, status: HttpStatus.OK };
});
}

Expand Down
2 changes: 1 addition & 1 deletion api/test/integration/users/users-me.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Users ME (e2e)', () => {
.patch(usersContract.updateMe.path)
.send({ name: newName })
.set('Authorization', `Bearer ${jwtToken}`);
expect(response.status).toBe(201);
expect(response.status).toBe(200);
expect(response.body.data.id).toEqual(user.id);
expect(response.body.data.name).toEqual(newName);

Expand Down
19 changes: 14 additions & 5 deletions api/test/utils/mocks/mock-email.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { IEmailServiceInterface } from '@api/modules/notifications/email/email-service.interface';
import {
IEmailServiceInterface,
SendMailDTO,
} from '@api/modules/notifications/email/email-service.interface';
import { Logger } from '@nestjs/common';

export class MockEmailService implements IEmailServiceInterface {
logger: Logger = new Logger(MockEmailService.name);

sendMail = jest.fn(async (): Promise<void> => {
this.logger.log('Mock Email sent');
return Promise.resolve();
});
sendMail =
typeof jest !== 'undefined'
? jest.fn(async (sendMailDTO: SendMailDTO): Promise<void> => {
this.logger.log('Mock Email sent', this.constructor.name);
return Promise.resolve();
})
: async (sendMailDTO: SendMailDTO): Promise<void> => {
this.logger.log('Mock Email sent', this.constructor.name);
return Promise.resolve();
};
}
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dependencies": {
"@hookform/resolvers": "3.9.0",
"@lukemorales/query-key-factory": "1.3.4",
"@radix-ui/react-alert-dialog": "1.1.2",
"@radix-ui/react-dialog": "1.1.2",
"@radix-ui/react-icons": "1.3.0",
"@radix-ui/react-label": "2.1.0",
"@radix-ui/react-separator": "1.1.0",
Expand Down
5 changes: 5 additions & 0 deletions client/src/app/auth/confirm-email/[token]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ConfirmEmailForm from "@/containers/auth/confirm-email/form";

export default function ConfirmEmailPage() {
return <ConfirmEmailForm />;
}
3 changes: 3 additions & 0 deletions client/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getServerSession } from "next-auth";

import { config } from "@/app/auth/api/[...nextauth]/config";

import Toaster from "@/components/ui/toast/toaster";

import LayoutProviders from "./providers";

const inter = Inter({ subsets: ["latin"] });
Expand All @@ -27,6 +29,7 @@ export default async function RootLayout({
<html lang="en">
<body className={inter.className}>
<main>{children}</main>
<Toaster />
</body>
</html>
</LayoutProviders>
Expand Down
16 changes: 16 additions & 0 deletions client/src/app/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import { QueryClient, dehydrate } from "@tanstack/react-query";
import { HydrationBoundary } from "@tanstack/react-query";

import { client } from "@/lib/query-client";
import { queryKeys } from "@/lib/query-keys";

import { auth } from "@/app/auth/api/[...nextauth]/config";

import Profile from "@/containers/profile";

export default async function ProfilePage() {
const queryClient = new QueryClient();
const session = await auth();

await queryClient.prefetchQuery({
queryKey: queryKeys.user.me(session?.user?.id as string).queryKey,
queryFn: () =>
client.user.findMe.query({
extraHeaders: {
authorization: `Bearer ${session?.accessToken as string}`,
},
}),
});

return (
<HydrationBoundary state={dehydrate(queryClient)}>
Expand Down
143 changes: 143 additions & 0 deletions client/src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
"use client";

import * as React from "react";

import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";

import { cn } from "@/lib/utils";

import { buttonVariants } from "@/components/ui/button";

const AlertDialog = AlertDialogPrimitive.Root;

const AlertDialogTrigger = AlertDialogPrimitive.Trigger;

const AlertDialogPortal = AlertDialogPrimitive.Portal;

const AlertDialogOverlay = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className,
)}
{...props}
ref={ref}
/>
));
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;

const AlertDialogContent = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
>(({ className, ...props }, ref) => (
<AlertDialogPortal>
<AlertDialogOverlay />
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className,
)}
{...props}
/>
</AlertDialogPortal>
));
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;

const AlertDialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className,
)}
{...props}
/>
);
AlertDialogHeader.displayName = "AlertDialogHeader";

const AlertDialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className,
)}
{...props}
/>
);
AlertDialogFooter.displayName = "AlertDialogFooter";

const AlertDialogTitle = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold", className)}
{...props}
/>
));
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;

const AlertDialogDescription = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
AlertDialogDescription.displayName =
AlertDialogPrimitive.Description.displayName;

const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Action
ref={ref}
className={cn(buttonVariants(), className)}
{...props}
/>
));
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;

const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Cancel
ref={ref}
className={cn(
buttonVariants({ variant: "outline" }),
"mt-2 sm:mt-0",
className,
)}
{...props}
/>
));
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;

export {
AlertDialog,
AlertDialogPortal,
AlertDialogOverlay,
AlertDialogTrigger,
AlertDialogContent,
AlertDialogHeader,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
};
Loading
Loading