From a7f8ddd1cb4a360d25bf41f0676ba62672f67312 Mon Sep 17 00:00:00 2001
From: Sam
Date: Fri, 18 Nov 2022 15:27:25 +0100
Subject: [PATCH] refactor: extract Notice to component
---
frontend/components/Notice.tsx | 56 ++++++++++++++++++++++++++++++++
frontend/pages/login/discord.tsx | 15 +++++----
2 files changed, 64 insertions(+), 7 deletions(-)
create mode 100644 frontend/components/Notice.tsx
diff --git a/frontend/components/Notice.tsx b/frontend/components/Notice.tsx
new file mode 100644
index 0000000..53b0d74
--- /dev/null
+++ b/frontend/components/Notice.tsx
@@ -0,0 +1,56 @@
+import { ReactNode } from "react";
+import { ButtonStyle } from "./Button";
+
+export type NoticeStyle = ButtonStyle;
+
+export interface Props {
+ header?: string;
+ style?: NoticeStyle;
+ children?: ReactNode;
+}
+
+export default function Notice(props: Props) {
+ if (props.style === undefined) {
+ return PrimaryNotice(props);
+ }
+
+ switch (props.style) {
+ case ButtonStyle.primary:
+ return PrimaryNotice(props);
+ case ButtonStyle.success:
+ return SuccessNotice(props);
+ case ButtonStyle.danger:
+ return DangerNotice(props);
+ }
+}
+
+function PrimaryNotice(props: Props) {
+ return (
+
+ {props.children}
+
+ );
+}
+
+function SuccessNotice(props: Props) {
+ return (
+
+ {props.children}
+
+ );
+}
+
+function DangerNotice(props: Props) {
+ return (
+
+ {props.header && (
+
+ {props.header}
+
+ )}
+
+ {props.children}
+
+
+ );
+}
diff --git a/frontend/pages/login/discord.tsx b/frontend/pages/login/discord.tsx
index 3974eff..63edfc3 100644
--- a/frontend/pages/login/discord.tsx
+++ b/frontend/pages/login/discord.tsx
@@ -8,6 +8,7 @@ import TextInput from "../../components/TextInput";
import Loading from "../../components/Loading";
import { stat } from "fs";
import Button, { ButtonStyle } from "../../components/Button";
+import Notice from "../../components/Notice";
interface CallbackResponse {
has_account: boolean;
@@ -97,12 +98,12 @@ export default function Discord() {
if (!state.ticket && !state.error) {
return ;
- } else if (state.error) {
+ } else if (!state.ticket && state.error) {
return (
-
-
Error: {state.error.message ?? state.error}
+
+ {state.error.message ?? state.error}
Try again?
-
+
);
}
@@ -137,10 +138,10 @@ export default function Discord() {
{state.error && (
-
-
Error: {state.error.message ?? state.error}
+
+ {state.error.message ?? state.error}
Try again?
-
+
)}