Skip to content

Commit

Permalink
display error when the aggregator bearer token is rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Oct 18, 2023
1 parent de75f6b commit 84321fe
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 191 deletions.
198 changes: 7 additions & 191 deletions app/src/aggregators/AggregatorDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
import {
Await,
useFetcher,
useLoaderData,
useNavigation,
useParams,
} from "react-router-dom";
import { Await, useLoaderData, useParams } from "react-router-dom";
import { Aggregator } from "../ApiClient";
import { AccountBreadcrumbs } from "../util";
import { LinkContainer } from "react-router-bootstrap";
import Breadcrumb from "react-bootstrap/Breadcrumb";
import React, { Suspense, useEffect, useState } from "react";
import React, { Suspense } from "react";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import {
ArrowRepeat,
CloudUpload,
Pencil,
PencilSquare,
Trash,
} from "react-bootstrap-icons";
import { CloudUpload } from "react-bootstrap-icons";
import Table from "react-bootstrap/Table";
import D from "../logo/color/svg/small.svg";
import Placeholder from "react-bootstrap/Placeholder";
import {
Button,
ButtonGroup,
FormControl,
FormGroup,
FormLabel,
Modal,
} from "react-bootstrap";
import { ButtonGroup } from "react-bootstrap";
import RotateBearerTokenButton from "./RotateBearerTokenButton";
import RenameAggregatorButton from "./RenameAggregatorButton";
import DeleteAggregatorButton from "./DeleteAggregatorButton";

function Breadcrumbs() {
const { aggregator } = useLoaderData() as {
Expand Down Expand Up @@ -174,171 +158,3 @@ export function WithAggregator({
</Suspense>
);
}

function RenameAggregatorButton() {
const navigation = useNavigation();

const [show, setShow] = useState(false);
const close = React.useCallback(() => setShow(false), []);
const open = React.useCallback(() => setShow(true), []);
const fetcher = useFetcher();

useEffect(() => {
if (fetcher.data) close();
}, [fetcher, close]);

return (
<>
<Button
variant="outline-secondary"
className="ml-auto"
size="sm"
onClick={open}
>
<PencilSquare /> Rename
</Button>
<Modal show={show} onHide={close}>
<fetcher.Form method="PATCH">
<Modal.Header closeButton>
<Modal.Title>
Rename{" "}
<WithAggregator>{({ name }) => `"${name}"`}</WithAggregator>
</Modal.Title>
</Modal.Header>
<Modal.Body>
<FormGroup controlId="name">
<FormLabel>Name</FormLabel>
<WithAggregator>
{({ name }) => (
<FormControl
name="name"
type="text"
data-1p-ignore
defaultValue={name}
/>
)}
</WithAggregator>
</FormGroup>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={close}>
Close
</Button>
<Button
variant="primary"
type="submit"
disabled={navigation.state === "submitting"}
>
<Pencil /> Edit
</Button>
</Modal.Footer>
</fetcher.Form>
</Modal>
</>
);
}

function RotateBearerTokenButton() {
const navigation = useNavigation();

const [show, setShow] = useState(false);
const close = React.useCallback(() => setShow(false), []);
const open = React.useCallback(() => setShow(true), []);
const fetcher = useFetcher();

useEffect(() => {
if (fetcher.data) close();
}, [fetcher, close]);

return (
<>
<Button
variant="outline-secondary"
className="ml-auto"
size="sm"
onClick={open}
>
<ArrowRepeat /> Rotate Token
</Button>
<Modal show={show} onHide={close}>
<fetcher.Form method="PATCH">
<Modal.Header closeButton>
<Modal.Title>
Rotate Bearer Token for{" "}
<WithAggregator>{({ name }) => `"${name}"`}</WithAggregator>
</Modal.Title>
</Modal.Header>
<Modal.Body>
<FormGroup controlId="bearer_token">
<FormLabel>New Bearer Token</FormLabel>
<FormControl name="bearer_token" type="text" />
</FormGroup>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={close}>
Close
</Button>
<Button
variant="primary"
type="submit"
disabled={navigation.state === "submitting"}
>
<ArrowRepeat /> Rotate
</Button>
</Modal.Footer>
</fetcher.Form>
</Modal>
</>
);
}

function DeleteAggregatorButton() {
const navigation = useNavigation();

const [show, setShow] = useState(false);
const close = React.useCallback(() => setShow(false), []);
const open = React.useCallback(() => setShow(true), []);
const fetcher = useFetcher();

useEffect(() => {
if (fetcher.data) close();
}, [fetcher, close]);

return (
<>
<Button
variant="outline-danger"
className="ml-auto"
size="sm"
onClick={open}
>
<Trash /> Delete
</Button>
<Modal show={show} onHide={close}>
<Modal.Header closeButton>
<Modal.Title>
Delete <WithAggregator>{({ name }) => `"${name}"`}</WithAggregator>?
</Modal.Title>
</Modal.Header>
<Modal.Body>
This aggregator will immediately be removed from the interface and no
new tasks can be created with it.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={close}>
Close
</Button>
<fetcher.Form method="delete">
<Button
variant="danger"
type="submit"
disabled={navigation.state === "submitting"}
>
<Trash /> Delete
</Button>
</fetcher.Form>
</Modal.Footer>
</Modal>
</>
);
}
56 changes: 56 additions & 0 deletions app/src/aggregators/DeleteAggregatorButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useFetcher, useNavigation } from "react-router-dom";
import React, { useEffect, useState } from "react";
import { Trash } from "react-bootstrap-icons";
import { Button, Modal } from "react-bootstrap";
import { WithAggregator } from "./AggregatorDetail";

export default function DeleteAggregatorButton() {
const navigation = useNavigation();

const [show, setShow] = useState(false);
const close = React.useCallback(() => setShow(false), []);
const open = React.useCallback(() => setShow(true), []);
const fetcher = useFetcher();

useEffect(() => {
if (fetcher.data) close();
}, [fetcher, close]);

return (
<>
<Button
variant="outline-danger"
className="ml-auto"
size="sm"
onClick={open}
>
<Trash /> Delete
</Button>
<Modal show={show} onHide={close}>
<Modal.Header closeButton>
<Modal.Title>
Delete <WithAggregator>{({ name }) => `"${name}"`}</WithAggregator>?
</Modal.Title>
</Modal.Header>
<Modal.Body>
This aggregator will immediately be removed from the interface and no
new tasks can be created with it.
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={close}>
Close
</Button>
<fetcher.Form method="delete">
<Button
variant="danger"
type="submit"
disabled={navigation.state === "submitting"}
>
<Trash /> Delete
</Button>
</fetcher.Form>
</Modal.Footer>
</Modal>
</>
);
}
74 changes: 74 additions & 0 deletions app/src/aggregators/RenameAggregatorButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { useFetcher, useNavigation } from "react-router-dom";
import React, { useEffect, useState } from "react";
import { Pencil, PencilSquare } from "react-bootstrap-icons";
import {
Button,
FormControl,
FormGroup,
FormLabel,
Modal,
} from "react-bootstrap";
import { WithAggregator } from "./AggregatorDetail";

export default function RenameAggregatorButton() {
const navigation = useNavigation();

const [show, setShow] = useState(false);
const close = React.useCallback(() => setShow(false), []);
const open = React.useCallback(() => setShow(true), []);
const fetcher = useFetcher();

useEffect(() => {
if (fetcher.data) close();
}, [fetcher, close]);

return (
<>
<Button
variant="outline-secondary"
className="ml-auto"
size="sm"
onClick={open}
>
<PencilSquare /> Rename
</Button>
<Modal show={show} onHide={close}>
<fetcher.Form method="PATCH">
<Modal.Header closeButton>
<Modal.Title>
Rename{" "}
<WithAggregator>{({ name }) => `"${name}"`}</WithAggregator>
</Modal.Title>
</Modal.Header>
<Modal.Body>
<FormGroup controlId="name">
<FormLabel>Name</FormLabel>
<WithAggregator>
{({ name }) => (
<FormControl
name="name"
type="text"
data-1p-ignore
defaultValue={name}
/>
)}
</WithAggregator>
</FormGroup>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={close}>
Close
</Button>
<Button
variant="primary"
type="submit"
disabled={navigation.state === "submitting"}
>
<Pencil /> Edit
</Button>
</Modal.Footer>
</fetcher.Form>
</Modal>
</>
);
}
Loading

0 comments on commit 84321fe

Please sign in to comment.