Skip to content

Commit

Permalink
Support locale switch in admin panel (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
byn9826 authored Aug 11, 2024
1 parent 155079c commit 0b60405
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 39 deletions.
23 changes: 21 additions & 2 deletions admin-panel/app/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
routeTool, typeTool,
} from 'tools'

const locale = localStorage.getItem('Locale')

const AuthSetup = ({ children }: PropsWithChildren) => {
const t = useTranslations()

Expand Down Expand Up @@ -71,7 +73,7 @@ const AuthSetup = ({ children }: PropsWithChildren) => {
}

if (!isAuthenticated) {
loginRedirect()
loginRedirect({ locale: locale ?? undefined })
return
}

Expand Down Expand Up @@ -99,6 +101,16 @@ const LayoutSetup = ({ children } : PropsWithChildren) => {
const locale = useCurrentLocale()
const { logoutRedirect } = useAuth()

useEffect(
() => {
localStorage.setItem(
'Locale',
locale,
)
},
[locale],
)

const handleLogout = () => {
logoutRedirect({ postLogoutRedirectUri: process.env.NEXT_PUBLIC_CLIENT_URI })
}
Expand Down Expand Up @@ -155,6 +167,13 @@ const LayoutSetup = ({ children } : PropsWithChildren) => {
>
{t('layout.scopes')}
</Navbar.Link>
<Navbar.Link
as={Link}
className='flex items-center h-6'
href={`/${locale === 'en' ? 'fr' : 'en'}${routeTool.Internal.Dashboard}`}
>
{locale === 'en' ? 'FR' : 'EN'}
</Navbar.Link>
<Navbar.Link
onClick={handleLogout}
href='#'
Expand All @@ -174,7 +193,7 @@ const Setup = ({ children } : PropsWithChildren) => {
return (
<AuthProvider
clientId={process.env.NEXT_PUBLIC_CLIENT_ID ?? ''}
redirectUri={`${process.env.NEXT_PUBLIC_CLIENT_URI}/en/dashboard`}
redirectUri={`${process.env.NEXT_PUBLIC_CLIENT_URI}/${locale || 'en'}/dashboard`}
serverUri={process.env.NEXT_PUBLIC_SERVER_URI ?? ''}
>
<AuthSetup>
Expand Down
2 changes: 1 addition & 1 deletion admin-panel/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { notFound } from 'next/navigation'
import { getRequestConfig } from 'next-intl/server'

const locales = ['en']
const locales = ['en', 'fr']

export default getRequestConfig(async ({ locale }: { locale:string}) => {
if (!locales.includes(locale)) notFound()
Expand Down
2 changes: 1 addition & 1 deletion admin-panel/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createMiddleware from 'next-intl/middleware'

export default createMiddleware({
locales: ['en'],
locales: ['en', 'fr'],
defaultLocale: 'en',
})

Expand Down
62 changes: 31 additions & 31 deletions admin-panel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion admin-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@heroicons/react": "^2.1.4",
"@melody-auth/react": "*",
"@melody-auth/react": "^0.0.6",
"@preact/signals-react": "^2.1.0",
"classnames": "^2.5.1",
"flowbite-react": "^0.10.1",
Expand Down
96 changes: 96 additions & 0 deletions admin-panel/translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"layout": {
"blocked": "Seul le super administrateur peut accéder à cette application.",
"brand": "Melody Auth",
"logout": "Déconnexion",
"users": "Gérer les utilisateurs",
"roles": "Gérer les rôles",
"apps": "Gérer les applications",
"scopes": "Gérer les portées",
"dashboard": "Tableau de bord"
},
"common": {
"enable": "Activer",
"disable": "Désactiver",
"disabled": "Désactivé",
"active": "Actif",
"property": "Propriété",
"value": "Valeur",
"createdAt": "Créé le",
"updatedAt": "Mis à jour le",
"create": "Créer",
"options": "Options :",
"save": "Enregistrer",
"delete": "Supprimer",
"system": "Système",
"note": "Remarque",
"previous": "Précédent",
"next": "Suivant",
"status": "Statut",
"fieldIsRequired": "Ce champ est requis.",
"deleteConfirm": "Êtes-vous sûr de vouloir supprimer {item} ?",
"deleteConfirmBtn": "Supprimer"
},
"dashboard": {
"configs": "Configurations système",
"configName": "Nom",
"configValue": "Valeur",
"configSeconds": "secondes",
"links": "Liens système",
"apiSwagger": "Swagger API S2S",
"systemInfo": "Informations système"
},
"apps": {
"title": "Applications",
"app": "Application",
"new": "Créer une application",
"clientId": "ID Client",
"clientSecret": "Secret Client",
"name": "Nom",
"status": "Statut",
"type": "Type",
"scopes": "Portées",
"redirectUris": "URIs de redirection"
},
"users": {
"title": "Utilisateurs",
"user": "Utilisateur",
"authId": "ID Auth",
"email": "Email",
"name": "Nom",
"locale": "Langue",
"status": "Statut",
"loginCount": "Nombre de connexions",
"emailVerified": "Email vérifié",
"firstName": "Prénom",
"lastName": "Nom",
"roles": "Rôles",
"resend": "Renvoyer l'email",
"sent": "Email envoyé",
"you": "Vous",
"consented": "Applications consenties",
"revokeConsent": "Révoquer",
"confirmRevoke": "Êtes-vous sûr de vouloir révoquer le consentement à {item} pour l'utilisateur actuel ?",
"noConsented": "Aucune application consentie pour l'instant.",
"noIP": "Pas d'IP",
"lockedIPs": "IPs verrouillées",
"unlock": "Déverrouiller tout"
},
"roles": {
"title": "Rôles",
"role": "Rôle",
"name": "Nom",
"status": "Statut",
"new": "Créer un rôle"
},
"scopes": {
"title": "Portées",
"scope": "Portée",
"name": "Nom",
"status": "Statut",
"type": "Type de client",
"new": "Créer une portée",
"locales": "Langues",
"localeNote": "Ceci sera affiché sur la page de consentement de l'application utilisateur."
}
}
2 changes: 1 addition & 1 deletion server/migrations/0001_creae_app_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ CREATE TABLE [app] (
"isActive" integer DEFAULT 1
);
CREATE UNIQUE INDEX idx_unique_app_clientId ON app (clientId) WHERE deletedAt IS NULL;
INSERT INTO app ("name", "type", "redirectUris") values ("Admin Panel (SPA)", "spa", "http://localhost:3000/en/dashboard");
INSERT INTO app ("name", "type", "redirectUris") values ("Admin Panel (SPA)", "spa", "http://localhost:3000/en/dashboard,http://localhost:3000/fr/dashboard");
INSERT INTO app ("name", "type") values ("Admin Panel (S2S)", "s2s");
2 changes: 1 addition & 1 deletion server/src/views/components/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Field = ({
/>
<p
id={`error-${name}`}
class='text-red hidden text-sm'>
class='text-red hidden text-sm w-text'>
</p>
</section>
)
Expand Down
2 changes: 1 addition & 1 deletion server/src/views/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Layout = ({
.rounded-lg { border-radius: 16px; }
.rounded-md { border-radius: 8px; }
.w-full { width: 100%; }
.w-text { width: 300px }
.w-text { width: 240px; }
.main {
background-color: lightgray;
height: 100vh;
Expand Down

0 comments on commit 0b60405

Please sign in to comment.