From 900c0c82fa6e5504584b89a46290d1b413fd1c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96ZT=C3=9CRK?= <76204082+iamsedatozturk@users.noreply.github.com> Date: Mon, 11 Aug 2025 16:14:33 +0300 Subject: [PATCH] =?UTF-8?q?SubDomain=20i=C3=A7in=20ayr=C4=B1=20Layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/components/layouts/Layouts.tsx | 3 ++- ui/src/utils/subdomain.ts | 24 ++++++++++++++++++++++++ ui/src/views/auth/Login.tsx | 19 +------------------ 3 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 ui/src/utils/subdomain.ts diff --git a/ui/src/components/layouts/Layouts.tsx b/ui/src/components/layouts/Layouts.tsx index 702d1851..9a5bab4d 100644 --- a/ui/src/components/layouts/Layouts.tsx +++ b/ui/src/components/layouts/Layouts.tsx @@ -14,6 +14,7 @@ import useDirection from '@/utils/hooks/useDirection' import useLocale from '@/utils/hooks/useLocale' import { useDynamicRoutes } from '@/routes/dynamicRoutesContext' import { useLocation } from 'react-router-dom' +import { hasSubdomain } from '@/utils/subdomain' export type LayoutType = | typeof LAYOUT_TYPE_CLASSIC @@ -61,7 +62,7 @@ const Layout = () => { }, [routes, currentPath]) const AppLayout = useMemo(() => { - if (authenticated && route?.routeType === 'protected') { + if ((authenticated && route?.routeType === 'protected') || hasSubdomain()) { return layouts[layoutType] } diff --git a/ui/src/utils/subdomain.ts b/ui/src/utils/subdomain.ts new file mode 100644 index 00000000..ce806164 --- /dev/null +++ b/ui/src/utils/subdomain.ts @@ -0,0 +1,24 @@ +const defaultSubDomain = 'KURS' + +export const getSubdomain = (): string | null => { + if (typeof window === 'undefined') return null + + const hostname = window.location.hostname + const parts = hostname.split('.') + + // localhost veya normal domain ise subdomain yok + if (hostname === 'localhost' || parts.length < 3) { + return null + } + + // Default subdomain ise null döndür + if (parts[0].toUpperCase() === defaultSubDomain) { + return null + } + + return parts[0].toUpperCase() +} + +export const hasSubdomain = (): boolean => { + return getSubdomain() !== null +} diff --git a/ui/src/views/auth/Login.tsx b/ui/src/views/auth/Login.tsx index cf711a0b..e319ed57 100644 --- a/ui/src/views/auth/Login.tsx +++ b/ui/src/views/auth/Login.tsx @@ -20,6 +20,7 @@ import { motion } from 'framer-motion' import { useEffect, useRef, useState } from 'react' import { useNavigate } from 'react-router-dom' import * as Yup from 'yup' +import { getSubdomain } from '@/utils/subdomain' type SignInFormSchema = { userName: string @@ -67,24 +68,6 @@ const Login = () => { const defaultSubDomain = 'KURS' - const getSubdomain = () => { - if (typeof window === 'undefined') return null - - const hostname = window.location.hostname - - const parts = hostname.split('.') - - if (hostname === 'localhost' || parts.length < 3) { - return null - } - - if (parts[0].toUpperCase() === defaultSubDomain) { - return null - } - - return parts[0].toUpperCase() - } - const onSignIn = async ( values: SignInFormSchema, { setSubmitting, isSubmitting, setFieldValue, setFieldTouched }: any,