Ends the war between tRPC and next-i18next (#939)

* Ends the war between tRPC and next-i18next

* Locale fixes

* Linting

* Linting

* trpc i18n (not working) (#942)

* simplify i18n handler and remove redundant(?) fn check

* split up viewer to a "logged in only" and "public"

* wip -- skip first render

Co-authored-by: Omar López <[email protected]>

* Linting

* I18n fixes

* We don't need serverSideTranslations in every page anymore

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Alex Johansson <[email protected]>
This commit is contained in:
authored and GitHub committed 2021-10-14 13:57:49 +03:00
1 parent 26f20e2397
commit 0861d7cc61
28 files changed
+243 -401

No files matched your search

+32 -34
View File
@@ -9,44 +9,42 @@ export default function AddToHomescreen() {
return null;
}
}
return (
!closeBanner && (
<div className="fixed sm:hidden bottom-0 inset-x-0 pb-2 sm:pb-5">
<div className="max-w-7xl mx-auto px-2 sm:px-6 lg:px-8">
<div className="p-2 rounded-lg shadow-lg sm:p-3" style={{ background: "#2F333D" }}>
<div className="flex items-center justify-between flex-wrap">
<div className="w-0 flex-1 flex items-center">
<span className="flex p-2 rounded-lg bg-opacity-30 bg-black">
<svg
className="h-7 w-7 text-indigo-500 fill-current"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 50 50"
enableBackground="new 0 0 50 50">
<path d="M30.3 13.7L25 8.4l-5.3 5.3-1.4-1.4L25 5.6l6.7 6.7z" />
<path d="M24 7h2v21h-2z" />
<path d="M35 40H15c-1.7 0-3-1.3-3-3V19c0-1.7 1.3-3 3-3h7v2h-7c-.6 0-1 .4-1 1v18c0 .6.4 1 1 1h20c.6 0 1-.4 1-1V19c0-.6-.4-1-1-1h-7v-2h7c1.7 0 3 1.3 3 3v18c0 1.7-1.3 3-3 3z" />
</svg>
return !closeBanner ? (
<div className="fixed sm:hidden bottom-0 inset-x-0 pb-2 sm:pb-5">
<div className="max-w-7xl mx-auto px-2 sm:px-6 lg:px-8">
<div className="p-2 rounded-lg shadow-lg sm:p-3" style={{ background: "#2F333D" }}>
<div className="flex items-center justify-between flex-wrap">
<div className="w-0 flex-1 flex items-center">
<span className="flex p-2 rounded-lg bg-opacity-30 bg-black">
<svg
className="h-7 w-7 text-indigo-500 fill-current"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 50 50"
enableBackground="new 0 0 50 50">
<path d="M30.3 13.7L25 8.4l-5.3 5.3-1.4-1.4L25 5.6l6.7 6.7z" />
<path d="M24 7h2v21h-2z" />
<path d="M35 40H15c-1.7 0-3-1.3-3-3V19c0-1.7 1.3-3 3-3h7v2h-7c-.6 0-1 .4-1 1v18c0 .6.4 1 1 1h20c.6 0 1-.4 1-1V19c0-.6-.4-1-1-1h-7v-2h7c1.7 0 3 1.3 3 3v18c0 1.7-1.3 3-3 3z" />
</svg>
</span>
<p className="ml-3 text-xs font-medium text-white">
<span className="inline">
Add this app to your home screen for faster access and improved experience.
</span>
<p className="ml-3 text-xs font-medium text-white">
<span className="inline">
Add this app to your home screen for faster access and improved experience.
</span>
</p>
</div>
</p>
</div>
<div className="order-2 flex-shrink-0 sm:order-3 sm:ml-2">
<button
onClick={() => setCloseBanner(true)}
type="button"
className="-mr-1 flex p-2 rounded-md hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-white">
<span className="sr-only">Dismiss</span>
<XIcon className="h-6 w-6 text-white" aria-hidden="true" />
</button>
</div>
<div className="order-2 flex-shrink-0 sm:order-3 sm:ml-2">
<button
onClick={() => setCloseBanner(true)}
type="button"
className="-mr-1 flex p-2 rounded-md hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-white">
<span className="sr-only">Dismiss</span>
<XIcon className="h-6 w-6 text-white" aria-hidden="true" />
</button>
</div>
</div>
</div>
</div>
)
);
</div>
) : null;
}
+10 -13
View File
@@ -1,21 +1,18 @@
import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
interface Props {
localeProp: string;
}
import { trpc } from "@lib/trpc";
const I18nLanguageHandler = ({ localeProp }: Props): null => {
/**
* Auto-switches locale client-side to the logged in user's preference
*/
const I18nLanguageHandler = (): null => {
const { i18n } = useTranslation("common");
const router = useRouter();
const { pathname } = router;
if (!localeProp)
console.warn(
`You may forgot to return 'localeProp' from 'getServerSideProps' or 'getStaticProps' in ${pathname}`
);
if (i18n.language !== localeProp) {
i18n.changeLanguage(localeProp);
const locale = trpc.useQuery(["viewer.i18n"]).data?.locale;
if (locale && i18n.language && i18n.language !== locale) {
if (typeof i18n.changeLanguage === "function") i18n.changeLanguage(locale);
}
return null;
};
+25 -17
View File
@@ -11,7 +11,7 @@ import {
import { signOut, useSession } from "next-auth/client";
import Link from "next/link";
import { useRouter } from "next/router";
import React, { Fragment, ReactNode, useEffect } from "react";
import React, { ReactNode, useEffect } from "react";
import { Toaster } from "react-hot-toast";
import LicenseBanner from "@ee/components/LicenseBanner";
@@ -49,6 +49,7 @@ function useMeQuery() {
function useRedirectToLoginIfUnauthenticated() {
const [session, loading] = useSession();
const router = useRouter();
const query = useMeQuery();
useEffect(() => {
if (!loading && !session) {
@@ -60,6 +61,27 @@ function useRedirectToLoginIfUnauthenticated() {
});
}
}, [loading, session, router]);
if (query.status !== "loading" && !query.data) {
router.replace("/auth/login");
}
}
function useRedirectToOnboardingIfNeeded() {
const [session, loading] = useSession();
const router = useRouter();
const query = useMeQuery();
const user = query.data;
useEffect(() => {
if (!loading && user) {
if (shouldShowOnboarding(user)) {
router.replace({
pathname: "/getting-started",
});
}
}
}, [loading, session, router, user]);
}
export function ShellSubHeading(props: {
@@ -90,20 +112,10 @@ export default function Shell(props: {
CTA?: ReactNode;
}) {
const router = useRouter();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
useRedirectToLoginIfUnauthenticated();
useRedirectToOnboardingIfNeeded();
const telemetry = useTelemetry();
const query = useMeQuery();
useEffect(
function redirectToOnboardingIfNeeded() {
if (query.data && shouldShowOnboarding(query.data)) {
router.push("/getting-started");
}
},
[query.data, router]
);
const navigation = [
{
@@ -142,11 +154,7 @@ export default function Shell(props: {
telemetry.withJitsu((jitsu) => {
return jitsu.track(telemetryEventTypes.pageView, collectPageParameters(router.asPath));
});
}, [telemetry]);
if (query.status !== "loading" && !query.data) {
router.replace("/auth/login");
}
}, [telemetry, router.asPath]);
const pageTitle = typeof props.heading === "string" ? props.heading : props.title;
+1 -6
View File
@@ -1,5 +1,4 @@
import { ArrowLeftIcon } from "@heroicons/react/solid";
import { EventType } from "@prisma/client";
import { useEffect, useRef, useState } from "react";
import showToast from "@lib/notification";
@@ -8,11 +7,7 @@ import { Webhook } from "@lib/webhook";
import Button from "@components/ui/Button";
import Switch from "@components/ui/Switch";
export default function EditTeam(props: {
webhook: Webhook;
eventTypes: EventType[];
onCloseEdit: () => void;
}) {
export default function EditTeam(props: { webhook: Webhook; onCloseEdit: () => void }) {
const [bookingCreated, setBookingCreated] = useState(
props.webhook.eventTriggers.includes("booking_created")
);