App directory #4

This commit is contained in:
Darren Clarke 2023-06-28 12:55:24 +00:00 committed by GitHub
parent 69706053c6
commit 4d743c5e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 223 additions and 107 deletions

View file

@ -1,3 +1,5 @@
"use client";
import { FC, useEffect } from "react";
import { CircularProgress, Typography, Grid } from "@mui/material";
import { signIn, signOut, getSession } from "next-auth/react";

View file

@ -1,7 +1,9 @@
"use client";
import { FC, PropsWithChildren, useEffect } from "react";
import { CircularProgress } from "@mui/material";
import { useSession } from "next-auth/react";
import { useRouter } from "next/router";
import { useRouter } from "next/navigation";
export const Auth: FC<PropsWithChildren> = ({ children }) => {
const router = useRouter();

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable react/display-name */
import { forwardRef } from "react";
import useDigitInput, { InputAttributes } from "react-digit-input";

View file

@ -1,12 +1,14 @@
"use client";
import { FC, useEffect, useState } from "react";
import { Admin, Resource } from "react-admin";
import { useApolloClient } from "@apollo/client";
import polyglotI18nProvider from "ra-i18n-polyglot";
import { ThemeProvider, createTheme } from "@mui/material";
import { metamigoDataProvider } from "../lib/dataprovider";
import { metamigoDataProvider } from "../_lib/dataprovider";
import { theme } from "./layout/themes";
import { Layout } from "./layout";
import englishMessages from "../i18n/en";
import englishMessages from "../_i18n/en";
import users from "./users";
import accounts from "./accounts";
import whatsappBots from "./whatsapp/bots";

View file

@ -0,0 +1,8 @@
"use client";
import { FC, PropsWithChildren } from "react";
import { SessionProvider } from "next-auth/react";
export const MultiProvider: FC<PropsWithChildren> = ({ children }) => (
<SessionProvider>{children}</SessionProvider>
);

View file

@ -1,3 +1,5 @@
"use client";
import { FC } from "react";
import { makeStyles } from "@mui/styles";
import {

View file

@ -1,3 +1,5 @@
"use client";
import { FC } from "react";
import {
List,

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable import/no-named-as-default */
/* eslint-disable import/no-anonymous-default-export */
import AccountIcon from "@mui/icons-material/AccountTree";

View file

@ -1,3 +1,5 @@
"use client";
import { forwardRef } from "react";
import { AppBar, UserMenu, MenuItemLink, useTranslate } from "react-admin";
import Typography from "@mui/material/Typography";

View file

@ -1,4 +1,5 @@
/* eslint-disable import/no-named-as-default */
"use client";
import { Layout as RaLayout, LayoutProps, Sidebar } from "react-admin";
import AppBar from "./AppBar";
import Menu from "./Menu";
@ -6,7 +7,7 @@ import { theme } from "./themes";
const CustomSidebar = (props: any) => <Sidebar {...props} size={200} />;
const Layout = (props: LayoutProps) => (
export const Layout = (props: LayoutProps) => (
<RaLayout
{...props}
appBar={AppBar}
@ -16,5 +17,3 @@ const Layout = (props: LayoutProps) => (
theme={theme}
/>
);
export default Layout;

View file

@ -1,3 +1,5 @@
"use client";
import { SVGProps } from "react";
const Logo = (props: SVGProps<SVGSVGElement>) => (

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable camelcase */
import { FC, useState } from "react";
// import { useSelector } from "react-redux";

View file

@ -1,3 +1,5 @@
"use client";
import { FC, PropsWithChildren, Fragment, ReactElement } from "react";
import ExpandMore from "@mui/icons-material/ExpandMore";
import List from "@mui/material/List";

View file

@ -1,3 +1,5 @@
"use client";
export { default as AppBar } from "./AppBar";
export { default as Layout } from "./Layout";
export { Layout } from "./Layout";
export { default as Menu } from "./Menu";

View file

@ -1,3 +1,5 @@
"use client";
import {
SimpleForm,
Create,
@ -6,7 +8,7 @@ import {
CreateProps,
} from "react-admin";
import { useSession } from "next-auth/react";
import { validateE164Number } from "../../../lib/phone-numbers";
import { validateE164Number } from "../../../_lib/phone-numbers";
const SignalBotCreate = (props: CreateProps) => {
const { data: session } = useSession();

View file

@ -1,3 +1,5 @@
"use client";
import { SimpleForm, Edit, TextInput, required, EditProps } from "react-admin";
const SignalBotEdit = (props: EditProps) => (

View file

@ -1,3 +1,5 @@
"use client";
import React, { useState } from "react";
import {
Show,
@ -28,7 +30,7 @@ import { SixDigitInput } from "../../DigitInput";
import {
sanitizeE164Number,
isValidE164Number,
} from "../../../lib/phone-numbers";
} from "../../../_lib/phone-numbers";
const Sidebar = ({ record }: any) => {
const [phoneNumber, setPhoneNumber] = useState("");

View file

@ -1,3 +1,5 @@
"use client";
import SignalBotIcon from "@mui/icons-material/ChatOutlined";
import SignalBotList from "./SignalBotList";
import SignalBotEdit from "./SignalBotEdit";

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable react/display-name */
import {
SelectInput,

View file

@ -1,3 +1,5 @@
"use client";
import { FC } from "react";
import {
SimpleForm,

View file

@ -1,3 +1,5 @@
"use client";
import { makeStyles } from "@mui/styles";
import {
SimpleForm,

View file

@ -1,3 +1,5 @@
"use client";
import UserIcon from "@mui/icons-material/People";
import UserList from "./UserList";
import UserEdit from "./UserEdit";

View file

@ -1,3 +1,5 @@
"use client";
import { SelectInput, useRecordContext } from "react-admin";
export const UserRoleInput = (props: any) => {

View file

@ -1,3 +1,5 @@
"use client";
import { List, Datagrid, DateField, TextField, ListProps } from "react-admin";
const ProviderList = (props: ListProps) => (

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable import/no-anonymous-default-export */
import ProviderIcon from "@mui/icons-material/Business";
import ProviderList from "./ProviderList";

View file

@ -1,3 +1,5 @@
"use client";
import { SelectInput } from "react-admin";
export const ProviderKindInput = (props: any) => (

View file

@ -1,3 +1,5 @@
"use client";
import { useInput } from "react-admin";
import React, { useState } from "react";
import dynamic from "next/dynamic";

View file

@ -1,3 +1,5 @@
"use client";
import VoiceLineIcon from "@mui/icons-material/PhoneCallback";
import VoiceLineList from "./VoiceLineList";
import VoiceLineEdit from "./VoiceLineEdit";

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable react/display-name */
import React, { useState, useEffect } from "react";
import PlayIcon from "@mui/icons-material/PlayCircleFilled";
@ -12,7 +14,7 @@ import {
TextField,
} from "react-admin";
import { IconButton, CircularProgress } from "@mui/material";
import absoluteUrl from "../../../lib/absolute-url";
import absoluteUrl from "../../../_lib/absolute-url";
import TwilioLanguages from "./twilio-languages";
type TTSProvider = (voice: any, language: any, prompt: any) => Promise<void>;

View file

@ -1,3 +1,5 @@
"use client";
import { List, Datagrid, DateField, TextField, ListProps } from "react-admin";
import { BackendIdField } from "./shared";

View file

@ -1,3 +1,5 @@
"use client";
import WebhookIcon from "@mui/icons-material/Send";
import WebhookList from "./WebhookList";
import WebhookEdit from "./WebhookEdit";

View file

@ -1,3 +1,5 @@
"use client";
import { SelectInput, required } from "react-admin";
import {

View file

@ -1,3 +1,5 @@
"use client";
import { List, Datagrid, TextField } from "react-admin";
const WhatsappAttachmentList = (props: any) => (

View file

@ -1,3 +1,5 @@
"use client";
import { Show, ShowProps, SimpleShowLayout, TextField } from "react-admin";
const WhatsappAttachmentShow = (props: ShowProps) => (

View file

@ -1,3 +1,5 @@
"use client";
import WhatsappAttachmentIcon from "@mui/icons-material/AttachFile";
import WhatsappAttachmentList from "./WhatsappAttachmentList";
import WhatsappAttachmentShow from "./WhatsappAttachmentShow";

View file

@ -1,7 +1,9 @@
"use client";
// import dynamic from "next/dynamic";
import { SimpleForm, Create, TextInput, required } from "react-admin";
import { useSession } from "next-auth/react";
import { validateE164Number } from "../../../lib/phone-numbers";
import { validateE164Number } from "../../../_lib/phone-numbers";
const WhatsappBotCreate = (props: any) => {
// const MuiPhoneNumber = dynamic(() => import("material-ui-phone-number"), {

View file

@ -1,3 +1,5 @@
"use client";
import { SimpleForm, Edit, TextInput, required, EditProps } from "react-admin";
const WhatsappBotEdit = (props: EditProps) => (

View file

@ -1,3 +1,5 @@
"use client";
import React, { useEffect, useState } from "react";
import {
Card,

View file

@ -1,3 +1,5 @@
"use client";
import WhatsappBotIcon from "@mui/icons-material/WhatsApp";
import WhatsappBotList from "./WhatsappBotList";
import WhatsappBotEdit from "./WhatsappBotEdit";

View file

@ -1,3 +1,5 @@
"use client";
/* eslint-disable react/display-name */
import {
SelectInput,

View file

@ -1,3 +1,5 @@
"use client";
import WhatsappMessageIcon from "@mui/icons-material/Message";
import WhatsappMessageList from "./WhatsappMessageList";
import WhatsappMessageShow from "./WhatsappMessageShow";

View file

@ -0,0 +1,16 @@
"use client";
import { FC } from "react";
import { ApolloProvider } from "@apollo/client";
import { apolloClient } from "app/_lib/apollo-client";
import dynamic from "next/dynamic";
const MetamigoAdmin = dynamic(() => import("app/_components/MetamigoAdmin"), {
ssr: false,
});
export const Admin:FC = () => (
<ApolloProvider client={apolloClient}>
<MetamigoAdmin />
</ApolloProvider>
);

View file

@ -0,0 +1,5 @@
import { Admin } from "./_components/Admin";
export default function Home() {
return <Admin />
}

View file

@ -1,14 +1,14 @@
import { NextApiRequest, NextApiResponse } from "next";
import { NextRequest } from "next/server";
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import GitHub from "next-auth/providers/github";
import GitLab from "next-auth/providers/gitlab";
import Cognito from "next-auth/providers/cognito";
import { loadConfig, IAppConfig } from "@digiresilience/metamigo-config";
import { MetamigoAdapter } from "../../../lib/nextauth-adapter";
import { CloudflareAccessProvider } from "../../../lib/cloudflare";
import { MetamigoAdapter } from "app/_lib/nextauth-adapter";
import { CloudflareAccessProvider } from "app/_lib/cloudflare";
const nextAuthOptions = (config: IAppConfig, req: NextApiRequest) => {
const nextAuthOptions = (config: IAppConfig, req: NextRequest) => {
const { nextAuth, cfaccess } = config;
const adapter = MetamigoAdapter(config);
const providers = [];
@ -16,7 +16,7 @@ const nextAuthOptions = (config: IAppConfig, req: NextApiRequest) => {
const { audience, domain } = cfaccess;
const cloudflareAccessEnabled = audience && domain;
if (cloudflareAccessEnabled)
providers.push(CloudflareAccessProvider(audience, domain, adapter, req));
providers.push(CloudflareAccessProvider(audience, domain, adapter, req as any));
else {
if (nextAuth.google?.id)
providers.push(
@ -78,11 +78,11 @@ const nextAuthOptions = (config: IAppConfig, req: NextApiRequest) => {
};
};
const nextAuth = async (
req: NextApiRequest,
res: NextApiResponse
): Promise<void> =>
// @ts-expect-error: Type mismatch
NextAuth(req, res, nextAuthOptions(await loadConfig(), req));
const handler = async (req: NextRequest) => {
const config = await loadConfig();
const authOptions = nextAuthOptions(config, req);
// @ts-expect-error: non-existent property
return NextAuth(authOptions)(req);
};
export default nextAuth;
export { handler as GET, handler as POST };

View file

@ -1,6 +1,6 @@
import { createProxyMiddleware } from "http-proxy-middleware";
export default createProxyMiddleware({
export const POST = createProxyMiddleware({
target:
process.env.NODE_ENV === "production"
? "http://metamigo-api:3001"
@ -28,9 +28,3 @@ export default createProxyMiddleware({
}
},
});
export const config = {
api: {
bodyParser: false,
},
};

View file

@ -1,6 +1,6 @@
import { createProxyMiddleware } from "http-proxy-middleware";
export default createProxyMiddleware({
const handler = createProxyMiddleware({
target:
process.env.NODE_ENV === "production"
? "http://metamigo-api:3001"
@ -30,8 +30,4 @@ export default createProxyMiddleware({
},
});
export const config = {
api: {
bodyParser: false,
},
};
export { handler as GET, handler as POST, handler as PUT, handler as DELETE};

View file

@ -0,0 +1,20 @@
import { ReactNode } from "react";
import "app/_styles/globals.css";
import { MultiProvider } from "./_components/MultiProvider";
type LayoutProps = {
children: ReactNode;
}
export default function Layout({ children }: LayoutProps) {
return (
<html lang="en">
<body>
<MultiProvider>
{children}
</MultiProvider>
</body>
</html>
);
}

View file

@ -1,8 +1,10 @@
"use client";
import { FC } from "react";
import { Button } from "@mui/material";
import { signIn, signOut, useSession } from "next-auth/react";
const MyComponent: FC = () => {
export const Login: FC = () => {
const { data: session } = useSession();
return (
@ -26,5 +28,3 @@ const MyComponent: FC = () => {
</>
);
};
export default MyComponent;

View file

@ -0,0 +1,5 @@
import { Login } from "./_components/Login";
export default function Page() {
return <Login />;
}

View file

@ -0,0 +1,3 @@
export default function Page() {
return null;
}

View file

@ -1,13 +0,0 @@
import "../styles/globals.css";
import { AppProps } from "next/app";
import { SessionProvider } from "next-auth/react";
function MetamigoStarter({ Component, pageProps }: AppProps) {
return (
<SessionProvider session={(pageProps as any).session}>
<Component {...pageProps} />
</SessionProvider>
);
}
export default MetamigoStarter;

View file

@ -1,15 +0,0 @@
import { ApolloProvider } from "@apollo/client";
import { apolloClient } from "../lib/apollo-client";
import dynamic from "next/dynamic";
const MetamigoAdmin = dynamic(() => import("../components/MetamigoAdmin"), {
ssr: false,
});
export default function Home() {
return (
<ApolloProvider client={apolloClient}>
<MetamigoAdmin />
</ApolloProvider>
);
}

View file

@ -1,29 +0,0 @@
import { NextPage } from "next";
import { Typography, Box, Button, Grid, Link } from "@mui/material";
import { FC, useEffect, PropsWithChildren } from "react";
import { useRouter } from "next/router";
export const RedirectToAdmin: FC<PropsWithChildren> = ({ children }) => {
const router = useRouter();
useEffect(() => {
router.push("/admin");
});
return <>{children}</>;
};
const Home: NextPage = () => (
<Box>
<Typography variant="h3">Metamigo</Typography>
<Grid container justifyContent="space-around" style={{ padding: 60 }}>
<Grid item>
<Link href="/admin">
<Button variant="contained">Admin</Button>
<RedirectToAdmin />
</Link>
</Grid>
</Grid>
</Box>
);
export default Home;

View file

@ -2,7 +2,11 @@
"extends": "tsconfig-link",
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
@ -17,9 +21,24 @@
"strict": true,
"baseUrl": ".",
"paths": {
"@/*": ["./*", "../../node_modules/*"]
}
"@/*": [
"./*",
"../../node_modules/*"
]
},
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}