From c2900df6e9092d769b1ad0326ad16ecf00b3cb14 Mon Sep 17 00:00:00 2001
From: SevicheCC <91365763+Sevichecc@users.noreply.github.com>
Date: Tue, 6 Jun 2023 02:47:14 +0800
Subject: [PATCH] feat: copy button
---
app/page.tsx | 10 ++----
components/DataDisplay.tsx | 44 +++++++++++++-----------
components/FormContainer.tsx | 16 +++++++++
components/InputForm.tsx | 18 ++++++----
components/{ => scopes}/ScopeItem.tsx | 0
components/{ => scopes}/ScopeSection.tsx | 2 +-
components/ui/copybutton.tsx | 40 +++++++++++++++++++++
hooks/useCreateApp.ts | 8 ++---
lib/types.ts | 9 +++--
9 files changed, 102 insertions(+), 45 deletions(-)
create mode 100644 components/FormContainer.tsx
rename components/{ => scopes}/ScopeItem.tsx (100%)
rename components/{ => scopes}/ScopeSection.tsx (98%)
create mode 100644 components/ui/copybutton.tsx
diff --git a/app/page.tsx b/app/page.tsx
index dcb852d..dbf843d 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -8,7 +8,7 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
-import DataDisplay from "@/components/DataDisplay";
+import FormContainer from "@/components/FormContainer";
export default function Home() {
return (
@@ -19,21 +19,15 @@ export default function Home() {
M-OAuth
Card Description
-
-
+
{/*
Card Footer
*/}
-
-
-
-
-
);
diff --git a/components/DataDisplay.tsx b/components/DataDisplay.tsx
index c752519..db9f277 100644
--- a/components/DataDisplay.tsx
+++ b/components/DataDisplay.tsx
@@ -1,40 +1,44 @@
-'use client'
+"use client";
-import useCreateApp from "@/hooks/useCreateApp";
-import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
-import { AppEntry } from "../lib/types";
-
-interface DataDisplayProps {
- appEntry: AppEntry;
-}
+import {
+ Table,
+ TableBody,
+ TableCaption,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import { AppEntry } from "@/lib/types";
+import { CopyButton } from "./ui/copybutton";
const renderTableRow = (label: string, value: string | undefined) => (
-
+
{label}
- {value}
+
+ {value}
+ {value && }
+
);
-const DataDisplay = () => {
- const { appEntry } = useCreateApp();
-
+const DataDisplay = ({ appEntry }: { appEntry: AppEntry }) => {
return (
- A list of your recent invoices.
- Data Name
+ Type
Value
{renderTableRow("ID", appEntry?.id)}
{renderTableRow("Name", appEntry?.name)}
- {renderTableRow("Website", appEntry?.website || '')}
- {renderTableRow("Redirect URI", appEntry?.redirectUri)}
- {renderTableRow("Client ID", appEntry?.clientId)}
- {renderTableRow("Client Secret", appEntry?.clientSecret)}
- {renderTableRow("Vapid Key", appEntry?.vapidKey)}
+ {renderTableRow("Website", appEntry?.website || "")}
+ {renderTableRow("Redirect URI", appEntry?.redirect_uri)}
+ {renderTableRow("Client ID", appEntry?.client_id)}
+ {renderTableRow("Client Secret", appEntry?.client_secret)}
+ {renderTableRow("Vapid Key", appEntry?.vapid_key)}
);
diff --git a/components/FormContainer.tsx b/components/FormContainer.tsx
new file mode 100644
index 0000000..076ae19
--- /dev/null
+++ b/components/FormContainer.tsx
@@ -0,0 +1,16 @@
+"use client";
+import InputForm from "@/components/InputForm";
+import DataDisplay from "@/components/DataDisplay";
+import useCreateApp from "@/hooks/useCreateApp";
+
+const FormContainer = () => {
+ const { appEntry, createApp } = useCreateApp();
+
+ return (
+ <>
+
+ {appEntry && }
+ >
+ );
+};
+export default FormContainer;
diff --git a/components/InputForm.tsx b/components/InputForm.tsx
index 2ea5c1a..73ee9c4 100644
--- a/components/InputForm.tsx
+++ b/components/InputForm.tsx
@@ -15,9 +15,8 @@ import {
FormMessage,
} from "@/components/ui/form";
-import ScopeSection from "@/components/ScopeSection";
+import ScopeSection from "@/components/scopes/ScopeSection";
import { scopesInfo } from "@/lib/utils";
-import useCreateApp from "@/hooks/useCreateApp";
const formSchema = z.object({
instance: z.string().trim(),
@@ -28,9 +27,11 @@ const formSchema = z.object({
});
export type FormSchema = z.infer;
+interface InputFormProps {
+ createApp: ({}: FormSchema) => Promise;
+}
-const InputForm = () => {
- const { createApp } = useCreateApp();
+const InputForm: React.FC = ({ createApp }) => {
const form = useForm({
resolver: zodResolver(formSchema),
defaultValues: {
@@ -43,7 +44,10 @@ const InputForm = () => {
return (
);
diff --git a/components/ScopeItem.tsx b/components/scopes/ScopeItem.tsx
similarity index 100%
rename from components/ScopeItem.tsx
rename to components/scopes/ScopeItem.tsx
diff --git a/components/ScopeSection.tsx b/components/scopes/ScopeSection.tsx
similarity index 98%
rename from components/ScopeSection.tsx
rename to components/scopes/ScopeSection.tsx
index b124ef5..cf85b8e 100644
--- a/components/ScopeSection.tsx
+++ b/components/scopes/ScopeSection.tsx
@@ -8,7 +8,7 @@ import {
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { Button } from "@/components/ui/button";
-import ScopeItem from "@/components/ScopeItem";
+import ScopeItem from "@/components/scopes/ScopeItem";
import { ScopeInfo } from "@/lib/types";
diff --git a/components/ui/copybutton.tsx b/components/ui/copybutton.tsx
new file mode 100644
index 0000000..32487ad
--- /dev/null
+++ b/components/ui/copybutton.tsx
@@ -0,0 +1,40 @@
+"use client";
+
+import { useEffect, useState } from "react";
+import { cn } from "@/lib/utils";
+import { Check, Copy } from "lucide-react";
+
+interface CopyButtonProps extends React.HTMLAttributes {
+ value: string;
+}
+
+const copyToClipboardWithMeta = (value: string, event?: Event) => {
+ navigator.clipboard.writeText(value);
+};
+
+export function CopyButton({ value, className, ...props }: CopyButtonProps) {
+ const [hasCopied, setHasCopied] = useState(false);
+
+ useEffect(() => {
+ setTimeout(() => {
+ setHasCopied(false);
+ }, 2000);
+ }, [hasCopied]);
+
+ return (
+
+ );
+}
diff --git a/hooks/useCreateApp.ts b/hooks/useCreateApp.ts
index 9ed10d6..a97c328 100644
--- a/hooks/useCreateApp.ts
+++ b/hooks/useCreateApp.ts
@@ -24,7 +24,6 @@ const useCreateApp = () => {
scopes: scopes?.join(" "),
};
- console.log("app,", app);
try {
let request = await fetch(`${instance}/api/v1/apps`, {
method: "POST",
@@ -41,14 +40,13 @@ const useCreateApp = () => {
} catch (error) {
throw new Error((error as MError).error);
}
- },
- []
+ },[]
);
- console.log(appEntry);
+
return {
appEntry,
createApp,
};
};
-export default useCreateApp;
+export default useCreateApp;
\ No newline at end of file
diff --git a/lib/types.ts b/lib/types.ts
index e98d67d..2c2193b 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -18,10 +18,9 @@ export interface ScopeInfo {
id: string;
name: string;
website: string | null;
- redirectUri: string;
- clientId: string;
- clientSecret: string;
- vapidKey: string;
+ redirect_uri: string;
+ client_id: string;
+ client_secret: string;
+ vapid_key: string;
}
-
\ No newline at end of file