Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
chore(Webhook): remove temporary webhook feature
Browse files Browse the repository at this point in the history
Signed-off-by: reslene <reslene@numary.com>
  • Loading branch information
reslene committed Nov 7, 2022
1 parent e8a4878 commit e9c93f6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 83 deletions.
110 changes: 55 additions & 55 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as React from "react";
import { ReactElement, useEffect, useState } from "react";
import * as React from 'react';
import { ReactElement, useEffect, useState } from 'react';

import { withEmotionCache } from "@emotion/react";
import { Home, Logout } from "@mui/icons-material";
import { withEmotionCache } from '@emotion/react';
import { Home, Logout } from '@mui/icons-material';
import {
Backdrop,
Box,
CircularProgress,
Typography,
unstable_useEnhancedEffect as useEnhancedEffect,
} from "@mui/material";
import { redirect } from "@remix-run/node";
} from '@mui/material';
import { redirect } from '@remix-run/node';
import {
Links,
Meta,
Expand All @@ -20,29 +20,30 @@ import {
ScrollRestoration,
useCatch,
useLoaderData,
} from "@remix-run/react";
import { LinksFunction, LoaderFunction } from "@remix-run/server-runtime";
import { camelCase, get } from "lodash";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
} from '@remix-run/react';
import { LinksFunction, LoaderFunction } from '@remix-run/server-runtime';
import { camelCase, get } from 'lodash';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';

import styles from "./root.css";
import { useOpen } from "./src/hooks/useOpen";
import styles from './root.css';
import { useOpen } from './src/hooks/useOpen';

import { LoadingButton, Snackbar, theme } from "@numaryhq/storybook";
import { LoadingButton, Snackbar, theme } from '@numaryhq/storybook';

import Layout from "~/src/components/Layout";
import { getRoute, OVERVIEW_ROUTE } from "~/src/components/Navbar/routes";
import ClientStyleContext from "~/src/contexts/clientStyleContext";
import { ServiceContext } from "~/src/contexts/service";
import Layout from '~/src/components/Layout';
import { getRoute, OVERVIEW_ROUTE } from '~/src/components/Navbar/routes';
import ClientStyleContext from '~/src/contexts/clientStyleContext';
import { ServiceContext } from '~/src/contexts/service';
import { useService } from '~/src/hooks/useService';
import {
Authentication,
CurrentUser,
errorsMap,
logger,
} from "~/src/utils/api";
import { ReactApiClient } from "~/src/utils/api.client";
import { createApiClient } from "~/src/utils/api.server";
} from '~/src/utils/api';
import { ReactApiClient } from '~/src/utils/api.client';
import { createApiClient } from '~/src/utils/api.server';
import {
AUTH_CALLBACK_ROUTE,
COOKIE_NAME,
Expand All @@ -56,23 +57,22 @@ import {
refreshToken,
State,
withSession,
} from "~/src/utils/auth.server";
import { useService } from "~/src/hooks/useService";
} from '~/src/utils/auth.server';

interface DocumentProps {
children: React.ReactNode;
title?: string;
}

export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }];
export const links: LinksFunction = () => [{ rel: 'stylesheet', href: styles }];

export const loader: LoaderFunction = async ({ request }) => {
const session = await getSession(request.headers.get("Cookie"));
const session = await getSession(request.headers.get('Cookie'));
const cookie = session.get(COOKIE_NAME);
const url = new URL(request.url);
const stateObject: State = { redirectTo: `${url.pathname}${url.search}` };
const buff = new Buffer(JSON.stringify(stateObject));
const stateAsBase64 = buff.toString("base64");
const stateAsBase64 = buff.toString('base64');
const openIdConfig = await getOpenIdConfig();

if (!cookie) {
Expand All @@ -93,18 +93,18 @@ export const loader: LoaderFunction = async ({ request }) => {
);
if (refresh.access_token) {
session.set(COOKIE_NAME, encrypt(refresh));
const api = await createApiClient(session, "");
const api = await createApiClient(session, '');
currentUser = await api.getResource<CurrentUser>(
openIdConfig.userinfo_endpoint
);
const payload = getJwtPayload(sessionHolder);
const pseudo =
currentUser && currentUser.email
? currentUser.email.split("@")[0]
? currentUser.email.split('@')[0]
: undefined;
currentUser = {
...currentUser,
avatarLetter: pseudo ? pseudo.split("")[0].toUpperCase() : undefined,
avatarLetter: pseudo ? pseudo.split('')[0].toUpperCase() : undefined,
pseudo,
scp: payload ? payload.scp : [],
};
Expand Down Expand Up @@ -138,30 +138,30 @@ const renderError = (
display="flex"
justifyContent="space-evenly"
sx={{
width: "100%",
height: "100%",
width: '100%',
height: '100%',
background: ({ palette }) => palette.neutral[0],
}}
>
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
alignSelf: "center",
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
alignSelf: 'center',
background: ({ palette }) => palette.neutral[0],
}}
>
<Typography variant="large3x" mb={3}>
{t("common.boundaries.title")}
{t('common.boundaries.title')}
</Typography>
<Typography variant="h2" mt={3}>
{message || t("common.boundaries.errorState.error.title")}
{message || t('common.boundaries.errorState.error.title')}
</Typography>
<Typography variant="body2" mt={3}>
{description || t("common.boundaries.errorState.error.description")}
{description || t('common.boundaries.errorState.error.description')}
</Typography>
<Box sx={{ display: "flex" }}>
<Box sx={{ display: 'flex' }}>
<LoadingButton
id="go-back-home"
content="Go back home"
Expand All @@ -172,7 +172,7 @@ const renderError = (
/>
<LoadingButton
id="logout"
content={t("topbar.logout")}
content={t('topbar.logout')}
variant="stroke"
startIcon={<Logout />}
onClick={() => {
Expand Down Expand Up @@ -210,7 +210,7 @@ const Document = withEmotionCache(
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="theme-color" content={theme.palette.primary.main} />
<title>{title || "Formance"}</title>
<title>{title || 'Formance'}</title>
<Meta />
<link
rel="stylesheet"
Expand Down Expand Up @@ -249,18 +249,18 @@ export default function App() {
const [loading, _load, stopLoading] = useOpen(true);
const [feedback, setFeedback] = useState({
active: false,
message: t("common.feedback.error"),
message: t('common.feedback.error'),
});

const displayFeedback = (message = "common.feedback.error") => {
const displayFeedback = (message = 'common.feedback.error') => {
setFeedback({ active: true, message: t(message) });
};

const handleClose = (
event: React.SyntheticEvent | Event,
reason?: string
) => {
if (reason === "clickaway") {
if (reason === 'clickaway') {
return;
}

Expand All @@ -272,9 +272,9 @@ export default function App() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (!global.timer) {
console.info("Global time not defined, installing it");
console.info('Global time not defined, installing it');
const refreshToken = (): Promise<any> => {
console.info("Trigger refresh authentication");
console.info('Trigger refresh authentication');

return fetch(`${metas.origin}/auth/refresh`)
.then((response) => response.json())
Expand All @@ -283,11 +283,11 @@ export default function App() {
)
.catch(async (reason) => {
if (reason?.status === 400) {
console.info("End session");
console.info('End session');
window.location.href = `${origin}/auth/redirect-logout`;
} else {
// retry one last time
console.info("Retry refresh");
console.info('Retry refresh');
const refresh = await fetch(`${metas.origin}/auth/refresh`);
switch (refresh?.status) {
case 200:
Expand All @@ -298,7 +298,7 @@ export default function App() {
return (window.location.href = `${origin}/auth/redirect-logout`);
}
}
console.info("Error refreshing token: ", reason);
console.info('Error refreshing token: ', reason);
});
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand All @@ -312,10 +312,10 @@ export default function App() {
{loading ? (
<Box
sx={{
display: "flex",
height: "100%",
justifyContent: "center",
alignItems: "center",
display: 'flex',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
background: theme.palette.neutral[0],
}}
>
Expand Down Expand Up @@ -349,7 +349,7 @@ export function ErrorBoundary({ error }: { error: Error }) {
const navigate = useNavigate();
const { t } = useTranslation();
const { metas } = useService();
logger(error, "app/root", undefined);
logger(error, 'app/root', undefined);

return (
<Document title="Error!">
Expand All @@ -364,7 +364,7 @@ export function CatchBoundary() {
const { t } = useTranslation();
const { metas } = useService();

logger(caught, "app/root/CatchBoundary");
logger(caught, 'app/root/CatchBoundary');

const error = camelCase(get(errorsMap, caught.status, errorsMap[422]));
const message = t(`common.boundaries.errorState.${error}.title`);
Expand Down
15 changes: 8 additions & 7 deletions app/routes/connectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { CreateForm as OAuthClientForm } from '~/routes/connectors/oauth-clients
import {
connectors as connectorsConfig,
OAUTH_CLIENTS_ROUTE,
WEBHOOKS_ROUTE,
} from '~/src/components/Navbar/routes';

export const meta: MetaFunction = () => ({
Expand Down Expand Up @@ -42,12 +41,14 @@ export default function Index() {
type: 'oAuthClients',
action: <OAuthClientForm />,
},
{
active: handleActive('webhooks'),
label: t('pages.connectors.tabs.webhooks.title'),
onClick: () => navigate(WEBHOOKS_ROUTE),
type: 'webhooks',
},
// TODO uncomment when feature is ready
// {
// active: handleActive('webhooks'),
// label: t('pages.connectors.tabs.webhooks.title'),
// onClick: () => navigate(WEBHOOKS_ROUTE),
// type: 'webhooks',
// action: <WebhookForm />,
// },
];

const activeConfig = config.find((item) => item.active);
Expand Down
42 changes: 21 additions & 21 deletions app/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FunctionComponent } from "react";
import React, { FunctionComponent } from 'react';

import { ArrowDropDown, Person } from "@mui/icons-material";
import { ArrowDropDown, Person } from '@mui/icons-material';
import {
Avatar,
Box,
Expand All @@ -9,22 +9,22 @@ import {
MenuItem,
Typography,
useTheme,
} from "@mui/material";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router-dom";
} from '@mui/material';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';

import Search from "./../Search";
import Search from './../Search';

import { Navbar as FormanceNavbar } from "@numaryhq/storybook";
import { Navbar as FormanceNavbar } from '@numaryhq/storybook';

import LinkWrapper from "../Wrappers/LinkWrapper";
import LinkWrapper from '../Wrappers/LinkWrapper';

import {
getRoute,
OVERVIEW_ROUTE,
routerConfig,
} from "~/src/components/Navbar/routes";
import { useService } from "~/src/hooks/useService";
} from '~/src/components/Navbar/routes';
import { useService } from '~/src/hooks/useService';

const Navbar: FunctionComponent = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -54,7 +54,7 @@ const Navbar: FunctionComponent = () => {
label: t(route.label),
}));

const settings = [t("topbar.logout")];
const settings = [t('topbar.logout')];

return (
<FormanceNavbar
Expand All @@ -63,17 +63,17 @@ const Navbar: FunctionComponent = () => {
routes={formattedRouterConfig}
location={location}
linkWrapper={
<LinkWrapper to={""} prefetch={"none"} color={""}>
<LinkWrapper to={''} prefetch={'none'} color={''}>
<Box />
</LinkWrapper>
}
>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
width: "120px",
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
width: '120px',
}}
>
<Search />
Expand All @@ -99,17 +99,17 @@ const Navbar: FunctionComponent = () => {
<ArrowDropDown sx={{ color: theme.palette.grey[500] }} />
</IconButton>
<Menu
sx={{ mt: "45px" }}
sx={{ mt: '45px' }}
id="menu-appbar"
anchorEl={anchorElUser}
anchorOrigin={{
vertical: "top",
horizontal: "right",
vertical: 'top',
horizontal: 'right',
}}
keepMounted
transformOrigin={{
vertical: "top",
horizontal: "right",
vertical: 'top',
horizontal: 'right',
}}
open={Boolean(anchorElUser)}
onClose={handleCloseUserMenu}
Expand Down

0 comments on commit e9c93f6

Please sign in to comment.