disable auto language detection;
disable languuage switch for now; Tweak some error logs and messages
This commit is contained in:
@ -39,7 +39,7 @@ const LanguageSwitcher = () => {
|
||||
open={Boolean(anchorEl)}
|
||||
onClose={handleClose}
|
||||
>
|
||||
{locales.map((lng) => {
|
||||
{locales?.map((lng) => {
|
||||
if (lng === locale) return null;
|
||||
return (
|
||||
<MenuItem key={lng} onClick={() => changeLanguage(lng)}>
|
||||
|
@ -10,9 +10,10 @@ interface ProtectedRouteProps {
|
||||
allowedRoles: UserRole[];
|
||||
deniedMessage?: string;
|
||||
bypass?: boolean;
|
||||
autoRedirect?: boolean;
|
||||
}
|
||||
|
||||
const ProtectedRoute = ({ children, allowedRoles, deniedMessage, bypass = false }: ProtectedRouteProps) => {
|
||||
const ProtectedRoute = ({ children, allowedRoles, deniedMessage, bypass = false, autoRedirect = false }: ProtectedRouteProps) => {
|
||||
const { data: session, status } = useSession()
|
||||
const router = useRouter();
|
||||
|
||||
@ -20,10 +21,9 @@ const ProtectedRoute = ({ children, allowedRoles, deniedMessage, bypass = false
|
||||
console.log("session.role:" + session?.user?.role);
|
||||
if (!status || status === "unauthenticated") {
|
||||
// Redirect to the sign-in page
|
||||
if (!bypass) {
|
||||
if (autoRedirect) {
|
||||
signIn();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
console.log("session.role:" + session?.user?.role);
|
||||
@ -41,14 +41,27 @@ const ProtectedRoute = ({ children, allowedRoles, deniedMessage, bypass = false
|
||||
if (deniedMessage !== undefined) {
|
||||
return <div>{deniedMessage}</div>;
|
||||
}
|
||||
return <div>Нямате достъп до тази страница. Ако мислите, че това е грешка, моля, свържете се с администраторите</div>;
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<div className="text-center">
|
||||
<h1 className="text-2xl font-bold mb-4 text-blue-500">{session?.user?.email},</h1>
|
||||
<p className="mb-6">{`Нямате достъп до тази страница. Ако мислите, че това е грешка, моля, свържете се с администраторите`}</p>
|
||||
</div>
|
||||
</div>
|
||||
</>);
|
||||
|
||||
}
|
||||
|
||||
if (status === "loading") {
|
||||
return <div>Зареждане...</div>;
|
||||
}
|
||||
if (!session) return <a href="/api/auth/signin">Защитено съдържание. Впишете се.. </a>
|
||||
return children;
|
||||
if (!session) {
|
||||
if (deniedMessage !== undefined) {
|
||||
return <div>{deniedMessage}</div>;
|
||||
}
|
||||
return <a href="/api/auth/signin">Защитено съдържание. Впишете се.. </a>
|
||||
}
|
||||
};
|
||||
|
||||
export default ProtectedRoute;
|
||||
|
@ -105,19 +105,22 @@ export default function Sidebar({ isSidebarOpen, toggleSidebar }) {
|
||||
useEffect(() => {
|
||||
const fetchLocations = async () => {
|
||||
try {
|
||||
const response = await axiosInstance.get('/api/data/locations'); // Adjust the API endpoint as needed
|
||||
const locationsData = response.data
|
||||
.filter(location => location.isActive === true)
|
||||
.map(location => ({
|
||||
text: location.name,
|
||||
url: `/cart/locations/${location.id}`,
|
||||
}));
|
||||
// Find the "Locations" menu item and populate its children with locationsData
|
||||
const menuIndex = sidemenu.findIndex(item => item.id === "locations");
|
||||
if (menuIndex !== -1) {
|
||||
sidemenu[menuIndex].children = locationsData;
|
||||
if (session) { // Don't fetch locations if the user is not authenticated
|
||||
|
||||
const response = await axiosInstance.get('/api/data/locations'); // Adjust the API endpoint as needed
|
||||
const locationsData = response.data
|
||||
.filter(location => location.isActive === true)
|
||||
.map(location => ({
|
||||
text: location.name,
|
||||
url: `/cart/locations/${location.id}`,
|
||||
}));
|
||||
// Find the "Locations" menu item and populate its children with locationsData
|
||||
const menuIndex = sidemenu.findIndex(item => item.id === "locations");
|
||||
if (menuIndex !== -1) {
|
||||
sidemenu[menuIndex].children = locationsData;
|
||||
}
|
||||
//setLocations(locationsData); // Optional, if you need to use locations elsewhere
|
||||
}
|
||||
//setLocations(locationsData); // Optional, if you need to use locations elsewhere
|
||||
} catch (error) {
|
||||
console.error("Error fetching locations:", error);
|
||||
}
|
||||
@ -174,16 +177,17 @@ function UserSection({ session }) {
|
||||
}
|
||||
|
||||
function SignInButton() {
|
||||
const t = useTranslations('common');
|
||||
// const t = useTranslations('common');
|
||||
return (
|
||||
<div className="items-center py-2 font-bold" onClick={() => signIn()}>
|
||||
<button>{t('login')}</button>
|
||||
<button>вход</button>
|
||||
{/* <button>{t('login')}</button> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UserDetails({ session }) {
|
||||
const t = useTranslations('common');
|
||||
// const t = useTranslations('common');
|
||||
return (
|
||||
<>
|
||||
<hr className="m-0" />
|
||||
@ -194,7 +198,10 @@ function UserDetails({ session }) {
|
||||
<div className="ml-3 overflow-hidden">
|
||||
<p className="mx-1 mt-1 text-sm font-medium text-gray-800 dark:text-gray-200">{session.user.name}</p>
|
||||
<p className="mx-1 mt-1 text-sm font-medium text-gray-600 dark:text-gray-400">{session.user.role}</p>
|
||||
<a href="/api/auth/signout" className={styles.button} onClick={(e) => { e.preventDefault(); signOut(); }}>{t('logout')}</a>
|
||||
<a href="/api/auth/signout" className={styles.button} onClick={(e) => { e.preventDefault(); signOut(); }}>
|
||||
{/* {t('logout')} */}
|
||||
изход
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
@ -56,6 +56,6 @@ module.exports = withPWA({
|
||||
// using https://next-intl-docs.vercel.app/docs/getting-started/pages-router
|
||||
locales: ['bg', 'en', 'ru'],
|
||||
defaultLocale: 'bg',
|
||||
autoDetect: false,
|
||||
localeDetection: false,
|
||||
},
|
||||
})
|
@ -28,26 +28,27 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
||||
export default function App({ Component, pageProps: { session, ...pageProps }, }: AppProps<{ session: Session }>) {
|
||||
// console.log(pageProps);
|
||||
const router = useRouter();
|
||||
const [locale, setLocale] = useState(router.locale || 'bg');
|
||||
const [messages, setMessages] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
console.log("Current locale:", router.locale);
|
||||
async function loadLocaleData() {
|
||||
// Replace the static import with a fetch request
|
||||
const res = await fetch(`/api/translations/${router.locale}`);
|
||||
const res = await fetch(`/api/translations/${locale}`);
|
||||
if (res.ok) {
|
||||
const localeMessages = await res.json();
|
||||
console.log("Loaded messages for locale:", router.locale, localeMessages);
|
||||
console.log("Loaded messages for locale:", locale, localeMessages);
|
||||
setMessages(localeMessages);
|
||||
} else {
|
||||
const localeMessages = await import(`../content/i18n/${router.locale}.json`); setMessages(localeMessages.default);
|
||||
const localeMessages = await import(`../content/i18n/${locale}.json`); setMessages(localeMessages.default);
|
||||
}
|
||||
console.log("Loaded locale '", router.locale, "' ",);
|
||||
console.log("Loaded locale '", locale, "' ",);
|
||||
//console.log("Loaded messages for locale:", router.locale, localeMessages.default);
|
||||
|
||||
}
|
||||
loadLocaleData();
|
||||
}, [router.locale]);
|
||||
}, [locale]);
|
||||
|
||||
// useEffect(() => {
|
||||
// async function loadLocaleData() {
|
||||
@ -101,7 +102,7 @@ export default function App({ Component, pageProps: { session, ...pageProps }, }
|
||||
return (
|
||||
<>
|
||||
<NextIntlClientProvider
|
||||
locale={router.locale}
|
||||
locale={'bg'}
|
||||
timeZone="Europe/Sofia"
|
||||
messages={messages}
|
||||
>
|
||||
@ -110,7 +111,7 @@ export default function App({ Component, pageProps: { session, ...pageProps }, }
|
||||
<Component {...pageProps} />
|
||||
</LocalizationProvider>
|
||||
</SessionProvider>
|
||||
</NextIntlClientProvider>
|
||||
</NextIntlClientProvider >
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'DELETE') {
|
||||
switch (targetTable) {
|
||||
case 'publishers':
|
||||
case 'availabilities':
|
||||
const targetId = req.query.nextcrud[1];
|
||||
logger.info('[nextCrud] ' + targetTable + ': ' + targetId + ' DELETED by ' + session.user.email);
|
||||
break;
|
||||
|
@ -49,7 +49,19 @@ export const getServerSideProps = async (context) => {
|
||||
}
|
||||
var url = process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/publishers/" + context.query.id + "?include=availabilities,assignments,assignments.shift";
|
||||
console.log("GET PUBLISHER FROM:" + url)
|
||||
const { data: item } = await axios.get(url);
|
||||
try {
|
||||
const { data: item } = await axios.get(url);
|
||||
} catch (error) {
|
||||
console.log("error fetching publisher: " + error);
|
||||
//redirect to message page with message "no account found". get user from session
|
||||
const user = context.req.session.user;
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/message?message=Този имейл (' + user.email + ') не е регистриран. Моля свържете се с администратора.',
|
||||
permanent: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// item.allShifts = item.assignments.map((a: Assignment[]) => a.shift);
|
||||
|
||||
|
Reference in New Issue
Block a user