mirror of
https://github.com/Sevichecc/m-oauth.git
synced 2025-04-30 06:59:29 +08:00
feat: auto scroll to result
This commit is contained in:
parent
a45c6f4f73
commit
409f35734a
3 changed files with 19 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import InputForm from "@/components/InputForm";
|
import InputForm from "@/components/InputForm";
|
||||||
import ResultTable from "@/components/tables/ResultTable";
|
import ResultTable from "@/components/tables/ResultTable";
|
||||||
import useCreateApp from "@/hooks/useCreateApp";
|
import useCreateApp from "@/hooks/useCreateApp";
|
||||||
|
@ -22,6 +22,7 @@ const FormContainer = () => {
|
||||||
scopes: [""],
|
scopes: [""],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card className="mt-5">
|
<Card className="mt-5">
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"use client";
|
|
||||||
|
|
||||||
import { TableCell, TableRow } from "@/components/ui/table";
|
import { TableCell, TableRow } from "@/components/ui/table";
|
||||||
import { CopyButton } from "@/components/ui/copybutton";
|
import { CopyButton } from "@/components/ui/copybutton";
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCaption,
|
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
|
@ -17,6 +16,8 @@ import { ExternalLink } from "lucide-react";
|
||||||
import { getAuth } from "@/lib/utils";
|
import { getAuth } from "@/lib/utils";
|
||||||
import { AppInfo } from "../FormContainer";
|
import { AppInfo } from "../FormContainer";
|
||||||
import { KeyRound } from "lucide-react";
|
import { KeyRound } from "lucide-react";
|
||||||
|
import { forwardRef } from "react";
|
||||||
|
import ClientOnly from "../ClientOnly";
|
||||||
interface ResultTableProps {
|
interface ResultTableProps {
|
||||||
credentials: Credentials;
|
credentials: Credentials;
|
||||||
appInfo: AppInfo;
|
appInfo: AppInfo;
|
||||||
|
@ -33,6 +34,7 @@ const renderTableRow = (label: string, value: string | undefined) => (
|
||||||
);
|
);
|
||||||
|
|
||||||
const ResultTable: React.FC<ResultTableProps> = ({ credentials, appInfo }) => {
|
const ResultTable: React.FC<ResultTableProps> = ({ credentials, appInfo }) => {
|
||||||
|
const scrollToRef = useRef<HTMLDivElement>(null);
|
||||||
const { instanceUrl, scopes } = appInfo;
|
const { instanceUrl, scopes } = appInfo;
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
|
@ -45,8 +47,15 @@ const ResultTable: React.FC<ResultTableProps> = ({ credentials, appInfo }) => {
|
||||||
} = credentials;
|
} = credentials;
|
||||||
|
|
||||||
const isLocal = redirect_uri === "urn:ietf:wg:oauth:2.0:oob";
|
const isLocal = redirect_uri === "urn:ietf:wg:oauth:2.0:oob";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (scrollToRef.current) {
|
||||||
|
scrollToRef.current.scrollIntoView({ behavior: "smooth" });
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center gap-5">
|
<div className="flex flex-col items-center gap-5" ref={scrollToRef}>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
@ -67,6 +76,11 @@ const ResultTable: React.FC<ResultTableProps> = ({ credentials, appInfo }) => {
|
||||||
)}
|
)}
|
||||||
</Table>
|
</Table>
|
||||||
{isLocal ? (
|
{isLocal ? (
|
||||||
|
<Button onClick={() => getAuth(instanceUrl, client_id, scopes)}>
|
||||||
|
<ExternalLink className="mr-2 h-4 w-4" />
|
||||||
|
Generate Access Token
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
<Alert>
|
<Alert>
|
||||||
<KeyRound className="h-4 w-4" />
|
<KeyRound className="h-4 w-4" />
|
||||||
<AlertTitle>Need an Access Token?</AlertTitle>
|
<AlertTitle>Need an Access Token?</AlertTitle>
|
||||||
|
@ -78,11 +92,6 @@ const ResultTable: React.FC<ResultTableProps> = ({ credentials, appInfo }) => {
|
||||||
to obtain your access token.
|
to obtain your access token.
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
) : (
|
|
||||||
<Button onClick={() => getAuth(instanceUrl, client_id, scopes)}>
|
|
||||||
<ExternalLink className="mr-2 h-4 w-4" />
|
|
||||||
Generate Access Token
|
|
||||||
</Button>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue