From 380cdb67464edbc73da82cd63199dcce73c6d776 Mon Sep 17 00:00:00 2001 From: Markusplay Date: Tue, 28 Jan 2025 23:06:36 +0200 Subject: [PATCH] refactor sublayout and profile page --- src/app/[locale]/(private)/profile/page.tsx | 44 +++++++++++++- .../[locale]/(private)/profile/profile.tsx | 58 ------------------- src/app/[locale]/(private)/sub-layout.tsx | 12 ++-- 3 files changed, 46 insertions(+), 68 deletions(-) delete mode 100644 src/app/[locale]/(private)/profile/profile.tsx diff --git a/src/app/[locale]/(private)/profile/page.tsx b/src/app/[locale]/(private)/profile/page.tsx index a00448d6..6f6c6998 100644 --- a/src/app/[locale]/(private)/profile/page.tsx +++ b/src/app/[locale]/(private)/profile/page.tsx @@ -1,9 +1,21 @@ 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'), @@ -11,8 +23,34 @@ export async function generateMetadata() { } export default async function Page() { + const t = await getTranslations(INTL_NAMESPACE); + + const user = await getUserDetails(); + const contacts = await getContacts(); const contactTypes = await getContactTypes(); - return ; + const isEmployee = !!user?.employeeProfile; + + return ( + +
+ {t('title')} + {t('subtitle')} +
+ + + + + + + + + + + +
+
+
+ ); } diff --git a/src/app/[locale]/(private)/profile/profile.tsx b/src/app/[locale]/(private)/profile/profile.tsx deleted file mode 100644 index 4e2e89fe..00000000 --- a/src/app/[locale]/(private)/profile/profile.tsx +++ /dev/null @@ -1,58 +0,0 @@ -'use client'; - -import { Heading1 } from '@/components/typography/headers'; -import { useTranslations } from 'next-intl'; -import { SubLayout } from '../sub-layout'; -import { Paragraph } from '@/components/typography/paragraph'; -import { InfoBlock } from '@/app/[locale]/(private)/profile/components/info-block'; -import { Contacts } from '@/app/[locale]/(private)/profile/components/contacts'; -import { Contact, ContactType } from '@/types/contact'; -import { IntellectAgreement } from '@/app/[locale]/(private)/profile/components/intellect-agreement'; -import { Card, CardContent } from '@/components/ui/card'; -import { IntellectPublicationInfo } from '@/app/[locale]/(private)/profile/components/intellect-publication-info'; -import { CodeOfHonor } from '@/app/[locale]/(private)/profile/components/code-of-honor'; -import { useLocalStorage } from '@/hooks/use-storage'; -import { User } from '@/types/user'; -import { useIsClient } from '@/hooks/use-is-client'; -import { Show } from '@/components/utils/show'; - -interface Props { - contacts: Contact[]; - contactTypes: ContactType[]; -} - -export function Profile({ contacts, contactTypes }: Props) { - const t = useTranslations('private.profile'); - - const [user] = useLocalStorage('user'); - - const isClient = useIsClient(); - - const isEmployee = !!user?.employeeProfile; - - if (!isClient) { - return null; - } - - return ( - -
- {t('title')} - {t('subtitle')} -
- - - - - - - - - - - -
-
-
- ); -} diff --git a/src/app/[locale]/(private)/sub-layout.tsx b/src/app/[locale]/(private)/sub-layout.tsx index 8dde2f3b..028e78c5 100644 --- a/src/app/[locale]/(private)/sub-layout.tsx +++ b/src/app/[locale]/(private)/sub-layout.tsx @@ -1,4 +1,3 @@ -'use client'; import { Breadcrumb, BreadcrumbItem, @@ -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 { @@ -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'); +export const SubLayout = async ({ children, breadcrumbs = [], pageTitle, className }: SubLayoutProps) => { + const t = await getTranslations('global.menu'); + const user = await getUserDetails(); if (!user?.codeOfHonorSignDate) { return ;