From 5bf506bb91fa4da27b525006f8e1f5fc54430783 Mon Sep 17 00:00:00 2001 From: Markusplay Date: Fri, 24 Jan 2025 01:29:43 +0200 Subject: [PATCH 1/2] change logout ui --- src/app/[locale]/(private)/header.tsx | 57 +++++++++---------- .../profile/components/info-block.tsx | 3 +- src/components/ui/locale-switch.tsx | 4 +- src/messages/en.json | 4 ++ src/messages/uk.json | 6 +- src/types/constants.ts | 4 +- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/app/[locale]/(private)/header.tsx b/src/app/[locale]/(private)/header.tsx index e941525c..bdc73154 100644 --- a/src/app/[locale]/(private)/header.tsx +++ b/src/app/[locale]/(private)/header.tsx @@ -8,23 +8,22 @@ import { Show } from '@/components/utils/show'; import { cn } from '@/lib/utils'; import { useLocalStorage } from '@/hooks/use-storage'; import { User } from '@/types/user'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuTrigger, -} from '@/components/ui/dropdown-menu'; import { Button } from '@/components/ui/button'; import { logout } from '@/actions/auth.actions'; import { useTranslations } from 'next-intl'; import { SignOut } from '@/app/images'; import { Paragraph } from '@/components/typography/paragraph'; +import { USER_CATEGORIES } from '@/types/constants'; +import React from 'react'; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; export const Header = () => { const isMobile = useIsMobile(); + const [user] = useLocalStorage('user'); + const t = useTranslations('private.profile'); + const tUserCategory = useTranslations('global.user-category'); const handleLogout = async () => { await logout(); @@ -41,29 +40,27 @@ export const Header = () => {
- - - - - - - - {user?.username} - - - - - - +
+ +
+ {user?.username} + {user?.userCategories.map((category) => ( + + {tUserCategory(USER_CATEGORIES[category])} + + ))} +
+
+ + + +
); diff --git a/src/app/[locale]/(private)/profile/components/info-block.tsx b/src/app/[locale]/(private)/profile/components/info-block.tsx index 7d426627..063dbddf 100644 --- a/src/app/[locale]/(private)/profile/components/info-block.tsx +++ b/src/app/[locale]/(private)/profile/components/info-block.tsx @@ -25,6 +25,7 @@ export function InfoBlock({ className }: Props) { const [user, setUser] = useLocalStorage('user'); const t = useTranslations('private.profile'); + const tUserCategory = useTranslations('global.user-category'); const { errorToast } = useServerErrorToast(); @@ -58,7 +59,7 @@ export function InfoBlock({ className }: Props) {
{user?.userCategories.map((category) => ( - {USER_CATEGORIES[category]} + {tUserCategory(USER_CATEGORIES[category])} ))} {studentProfile?.status && {studentProfile.status}} diff --git a/src/components/ui/locale-switch.tsx b/src/components/ui/locale-switch.tsx index 47e6232c..c53dcf8c 100644 --- a/src/components/ui/locale-switch.tsx +++ b/src/components/ui/locale-switch.tsx @@ -13,13 +13,13 @@ export const LocaleSwitch = () => { case LOCALE.UK: return ( <> - Switch to English + Switch to English ); default: return ( <> - Перейти на українську + Перейти на українську ); } diff --git a/src/messages/en.json b/src/messages/en.json index ea77de60..7cc80d12 100644 --- a/src/messages/en.json +++ b/src/messages/en.json @@ -45,6 +45,10 @@ "terms-of-service": "Terms of service", "contacts": "Contacts" }, + "user-category": { + "student": "Student", + "spw": "SPW" + }, "footer": "Developer: KBIS© {year} Igor Sikorsky Kyiv Polytechnic Institute", "goto-old": "Go to the old version of Campus" }, diff --git a/src/messages/uk.json b/src/messages/uk.json index 2622563d..ccbd0d6c 100644 --- a/src/messages/uk.json +++ b/src/messages/uk.json @@ -45,6 +45,10 @@ "terms-of-service": "Правила використання", "contacts": "Контакти" }, + "user-category": { + "student": "Студент", + "spw": "НПП" + }, "footer": "Розробник: КБІС© {year} КПІ ім. Ігоря Сікорського", "goto-old": "Перейти на стару версію Кампусу" }, @@ -232,7 +236,7 @@ "add-new": "Додати новий", "edit": "Редагувати", "agree": "Погоджуюсь", - "logout": "Вийти з акаунту" + "logout": "Вийти" }, "placeholder": { "credo": "Введіть улюблену цитату", diff --git a/src/types/constants.ts b/src/types/constants.ts index 46aa0041..11bfe4b9 100644 --- a/src/types/constants.ts +++ b/src/types/constants.ts @@ -12,8 +12,8 @@ export enum EmploymentType { } export const USER_CATEGORIES = { - [UserCategories.Student]: 'Студент', - [UserCategories.Lecturer]: 'Науково-педагогічний працівник', + [UserCategories.Student]: 'student', + [UserCategories.Lecturer]: 'spw', // SPW stands for scientific and pedagogical worker }; export const EMPLOYMENT_TYPE = { From db9119fc47d079bd1450483975fed031edd2e927 Mon Sep 17 00:00:00 2001 From: Markusplay Date: Fri, 24 Jan 2025 23:27:56 +0200 Subject: [PATCH 2/2] refactor --- src/components/ui/locale-switch.tsx | 20 ++++++++++---------- src/types/constants.ts | 6 +++--- src/types/user.ts | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/components/ui/locale-switch.tsx b/src/components/ui/locale-switch.tsx index c53dcf8c..ba4565fb 100644 --- a/src/components/ui/locale-switch.tsx +++ b/src/components/ui/locale-switch.tsx @@ -3,6 +3,14 @@ import { Link, LOCALE, usePathname } from '@/i18n/routing'; import { useLocale } from 'next-intl'; import { FlagGB, FlagUA } from '@/app/images'; +import { ReactNode } from 'react'; + +const LocaleOption = ({ text, icon }: { text: string; icon: ReactNode }) => ( + <> + {text} + {icon} + +); export const LocaleSwitch = () => { const locale = useLocale(); @@ -11,17 +19,9 @@ export const LocaleSwitch = () => { const getTitle = () => { switch (locale) { case LOCALE.UK: - return ( - <> - Switch to English - - ); + return } />; default: - return ( - <> - Перейти на українську - - ); + return } />; } }; diff --git a/src/types/constants.ts b/src/types/constants.ts index 11bfe4b9..ace6c825 100644 --- a/src/types/constants.ts +++ b/src/types/constants.ts @@ -1,4 +1,4 @@ -export enum UserCategories { +export enum UserCategory { Student = 'Student', Lecturer = 'Lecturer', } @@ -12,8 +12,8 @@ export enum EmploymentType { } export const USER_CATEGORIES = { - [UserCategories.Student]: 'student', - [UserCategories.Lecturer]: 'spw', // SPW stands for scientific and pedagogical worker + [UserCategory.Student]: 'student', + [UserCategory.Lecturer]: 'spw', // SPW stands for scientific and pedagogical worker }; export const EMPLOYMENT_TYPE = { diff --git a/src/types/user.ts b/src/types/user.ts index 10d67668..e42a6406 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -1,6 +1,6 @@ import { StudentProfile } from '@/types/student-profile'; import { EmployeeProfile } from '@/types/employee-profile'; -import { UserCategories } from '@/types/constants'; +import { UserCategory } from '@/types/constants'; export interface User { id: number; @@ -16,7 +16,7 @@ export interface User { modules: string[]; intellectProfileEnabled: boolean; intellectProfile?: string; - userCategories: UserCategories[]; + userCategories: UserCategory[]; codeOfHonorSignDate: string; studentProfile?: StudentProfile; employeeProfile?: EmployeeProfile;