Skip to content

Commit

Permalink
refactor sublayout and profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
Markusplay committed Jan 28, 2025
1 parent 87c27bc commit 380cdb6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 68 deletions.
44 changes: 41 additions & 3 deletions src/app/[locale]/(private)/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
import { getContacts, getContactTypes } from '@/actions/profile.actions';
import { Profile } from '@/app/[locale]/(private)/profile/profile';
import { getTranslations } from 'next-intl/server';
import { SubLayout } from '@/app/[locale]/(private)/sub-layout';
import { getUserDetails } from '@/actions/auth.actions';
import { Heading1 } from '@/components/typography/headers';
import { Paragraph } from '@/components/typography/paragraph';
import { InfoBlock } from '@/app/[locale]/(private)/profile/components/info-block';
import { Card, CardContent } from '@/components/ui/card';
import { Contacts } from '@/app/[locale]/(private)/profile/components/contacts';
import { Show } from '@/components/utils/show';
import { IntellectAgreement } from '@/app/[locale]/(private)/profile/components/intellect-agreement';
import { IntellectPublicationInfo } from '@/app/[locale]/(private)/profile/components/intellect-publication-info';
import { CodeOfHonor } from '@/app/[locale]/(private)/profile/components/code-of-honor';

const INTL_NAMESPACE = 'private.profile';

export async function generateMetadata() {
const t = await getTranslations({ namespace: 'private.profile' });
const t = await getTranslations(INTL_NAMESPACE);

return {
title: t('title'),
};
}

export default async function Page() {
const t = await getTranslations(INTL_NAMESPACE);

const user = await getUserDetails();

const contacts = await getContacts();
const contactTypes = await getContactTypes();

return <Profile contacts={contacts} contactTypes={contactTypes} />;
const isEmployee = !!user?.employeeProfile;

return (
<SubLayout pageTitle={t('title')}>
<div className="col-span-12">
<Heading1>{t('title')}</Heading1>
<Paragraph className="text-neutral-700">{t('subtitle')}</Paragraph>
<div className="flex flex-col gap-5 xl:flex-row">
<InfoBlock className="h-fit w-full" />
<Card className="h-fit w-full">
<CardContent className="flex flex-col gap-6 space-y-1.5 p-9">
<Contacts contacts={contacts} contactTypes={contactTypes} />
<Show when={isEmployee}>
<IntellectAgreement />
<IntellectPublicationInfo />
</Show>
<CodeOfHonor />
</CardContent>
</Card>
</div>
</div>
</SubLayout>
);
}
58 changes: 0 additions & 58 deletions src/app/[locale]/(private)/profile/profile.tsx

This file was deleted.

12 changes: 5 additions & 7 deletions src/app/[locale]/(private)/sub-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import {
Breadcrumb,
BreadcrumbItem,
Expand All @@ -8,10 +7,9 @@ import {
BreadcrumbSeparator,
} from '@/components/ui/breadcrumb';
import { cn } from '@/lib/utils';
import { useTranslations } from 'next-intl';
import React from 'react';
import { useLocalStorage } from '@/hooks/use-storage';
import { User } from '@/types/user';
import { getTranslations } from 'next-intl/server';
import { getUserDetails } from '@/actions/auth.actions';
import CodeOfHonorAlert from '@/components/code-of-honor-alert';

interface SubLayoutProps {
Expand All @@ -21,9 +19,9 @@ interface SubLayoutProps {
className?: string;
}

export const SubLayout = ({ children, breadcrumbs = [], pageTitle, className }: SubLayoutProps) => {
const t = useTranslations('global.menu');
const [user] = useLocalStorage<User>('user');
export const SubLayout = async ({ children, breadcrumbs = [], pageTitle, className }: SubLayoutProps) => {
const t = await getTranslations('global.menu');
const user = await getUserDetails();

if (!user?.codeOfHonorSignDate) {
return <CodeOfHonorAlert />;
Expand Down

0 comments on commit 380cdb6

Please sign in to comment.