Benja
Benja
TTCTheo's Typesafe Cult
Created by futurama on 12/26/2023 in #questions
Is there any example of implementation of external API usage?
5 replies
TTCTheo's Typesafe Cult
Created by Benja on 12/25/2023 in #questions
Web + Mobile + tRPC API
Finally I ended using this Supabase template with turborepo. Though that was only for mobile but it handles multiple client and fits with what I was looking for: https://github.com/supabase-community/create-t3-turbo
2 replies
TTCTheo's Typesafe Cult
Created by Tribe on 12/25/2023 in #questions
Adding Supabase to TRPC context
https://github.com/supabase-community/create-t3-turbo This might help you. Got it working some hours ago with a Supabase project
11 replies
TTCTheo's Typesafe Cult
Created by Cxstum on 12/26/2023 in #questions
How to implement tracking link in Next Js
There are several tools for tracking user navigations. Mixpanel could be a good option, but there might be better options like that one and even cheaper
2 replies
RRefine
Created by absent-sapphire on 11/29/2022 in #ask-any-question
How to change the label and icon of the default button that goes back to list in Show
Is there a way to go back to the list page but adding query params for example ?
6 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
beacuse that comes with the app foldering and on t3 stack version we used it's whitout it. So you can't set a layout.js file for this foldering structure. Thast one of the advantages of using the new Next.js version
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
Thats great @FilipN !! I will try it out for sure, thanks for your advice
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
Well is not like a pattern itself. Functions are like object variables and you are setting the layout at Component.getLayout and as you are setting this layouts on you components, they are rendering at _app flow to get layout and set it's corresponding children. I guess that's you are asking for
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
3 - Use it on your dynamic routes! Well here I made the folder src/pages/admin/[id] so I can use dynamic ids of business on the admin section line http://myurl.com/admin/123456/dashboard or /table or /users. So for this I created in the folder src/pages/admin/[id] every section file like dashboard.tsx, table.tsx, users.tsx so it gets on the routing 4 - Section config for layout usage!! This is the important part and what I said it was a bit unconfortable: setting the layout on every section manually. Here is one of the sections with the layout setting:
import React from 'react'
import AdminDashboard from '~/layouts/AdminLayout';

const UsersSection = () => {
return (
<div>UsersSection</div>
)
}

UsersSection.getLayout = (page: any) => (
<AdminDashboard>{page}</AdminDashboard>
);

export default UsersSection
import React from 'react'
import AdminDashboard from '~/layouts/AdminLayout';

const UsersSection = () => {
return (
<div>UsersSection</div>
)
}

UsersSection.getLayout = (page: any) => (
<AdminDashboard>{page}</AdminDashboard>
);

export default UsersSection
5 - And thats all !! Maybe if you are doing similar to my project you would like to set a default route to urls like http://myurl.com/admin/123456 because if this folder ( src/pages/admin/[id] ) doesn't have an index.tsx file it will not respond as you would expect. So I made a config at next.config.mjs to get the flow i wanted like setting the /dashboard section as default when accessing http://myurl.com/admin/[id] directly, here is my approach:
/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: false,

/**
* If you have `experimental: { appDir: true }` set, then you must comment the below `i18n` config
* out.
*
* @see https://github.com/vercel/next.js/issues/41980
*/
i18n: {
locales: ['en'],
defaultLocale: 'en',
},
redirects: async () => {
return [
{
source: '/admin',
destination: '/',
permanent: true,
},
{
source: '/admin/:id',
destination: '/admin/:id/dashboard',
permanent: true,
},
];
},
};
export default config;
/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: false,

/**
* If you have `experimental: { appDir: true }` set, then you must comment the below `i18n` config
* out.
*
* @see https://github.com/vercel/next.js/issues/41980
*/
i18n: {
locales: ['en'],
defaultLocale: 'en',
},
redirects: async () => {
return [
{
source: '/admin',
destination: '/',
permanent: true,
},
{
source: '/admin/:id',
destination: '/admin/:id/dashboard',
permanent: true,
},
];
},
};
export default config;
Hope this guide helps you !!
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
2 - Create your layout! In my case I created the folder layouts at src/layouts with a custom layout, but here I give you a basic one so you can try it out
import React, { ReactNode } from 'react';
interface AdminLayoutProps {
children: ReactNode;
}
const AdminLayout = ({ children }: AdminLayoutProps) => {
return (
<div style={{ display: 'flex', minHeight: '100vh' }}>
<nav
style={{
backgroundColor: '#1E293B',
color: 'white',
minWidth: '16rem',
padding: '2rem',
}}
>
{/* Sidebar content */}
</nav>
<main style={{ flex: 1, padding: '2rem' }}>
{/* Main content */}
{children}
</main>
</div>
);
};
export default AdminLayout;
import React, { ReactNode } from 'react';
interface AdminLayoutProps {
children: ReactNode;
}
const AdminLayout = ({ children }: AdminLayoutProps) => {
return (
<div style={{ display: 'flex', minHeight: '100vh' }}>
<nav
style={{
backgroundColor: '#1E293B',
color: 'white',
minWidth: '16rem',
padding: '2rem',
}}
>
{/* Sidebar content */}
</nav>
<main style={{ flex: 1, padding: '2rem' }}>
{/* Main content */}
{children}
</main>
</div>
);
};
export default AdminLayout;
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
Sure!! I will share you my files so adapt them to your structure and usage 1 - Config your _app to use the component layout
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { type AppType } from 'next/app';
import { type Session } from 'next-auth';
import { SessionProvider } from 'next-auth/react';
import { ChakraProvider } from '@chakra-ui/react';
import { api } from '~/utils/api';
import { appTheme } from '~/theme/theme';

import '~/styles/globals.css';
import Head from 'next/head';

const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
// Create this method to get component layout
const getLayout =
//@ts-ignore
(Component?.getLayout as unknown) ?? ((page: unknown) => page);

return (
<ChakraProvider theme={appTheme} resetCSS>
<SessionProvider session={session}>
{
// In my case this line throws an error but nothing to worry just ignore it and
//call the created method
//@ts-ignore
getLayout(<Component {...pageProps} />)
}
</SessionProvider>
</ChakraProvider>
);
};
export default api.withTRPC(MyApp);
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { type AppType } from 'next/app';
import { type Session } from 'next-auth';
import { SessionProvider } from 'next-auth/react';
import { ChakraProvider } from '@chakra-ui/react';
import { api } from '~/utils/api';
import { appTheme } from '~/theme/theme';

import '~/styles/globals.css';
import Head from 'next/head';

const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
// Create this method to get component layout
const getLayout =
//@ts-ignore
(Component?.getLayout as unknown) ?? ((page: unknown) => page);

return (
<ChakraProvider theme={appTheme} resetCSS>
<SessionProvider session={session}>
{
// In my case this line throws an error but nothing to worry just ignore it and
//call the created method
//@ts-ignore
getLayout(<Component {...pageProps} />)
}
</SessionProvider>
</ChakraProvider>
);
};
export default api.withTRPC(MyApp);
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
Updating this issue: I implemented the getLayout approach and it worked well. Layout doesn't re-render and working great. A bit unconfortable to set manually the layout for all leafs on the directory files but not a big deal. Idk if it will be easy to migrate to further versions with new layout management.
24 replies
TTCTheo's Typesafe Cult
Created by Benja on 4/23/2023 in #questions
Layout management - T3 Stack - Next.js v13
I saw this approach but I dont understand completly how this fits with the folder routing. For example: I have this foldering src/pages/admin -- this folder will have all the admin sections I guess like "settings.tsx" so when accesing to "url.com/admin/settings will show that component and if I set the layout there when moving to other section like "url.com/admin/table" wil render the other component and layout again without persistance aka rerendering layout, isn't it ?
24 replies
RRefine
Created by frozen-sapphire on 12/7/2022 in #ask-any-question
Make useSearchParams() hook available in pankodrefine-react-router-v6
I tried the command for migration, it works great but the routing and foldering has to be manual and it will take me a while
21 replies