|
| 1 | +import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table"; |
| 2 | +import Link from "next/link"; |
| 3 | +import { getBridgePaths } from "./utils"; |
| 4 | + |
| 5 | +export default async function Page() { |
| 6 | + try { |
| 7 | + const paths = await getBridgePaths(); |
| 8 | + return ( |
| 9 | + <div className="pb-20"> |
| 10 | + <h2 className="mb-2 font-semibold text-2xl tracking-tight"> |
| 11 | + Universal Bridge REST API |
| 12 | + </h2> |
| 13 | + <p className="mb-5 text-muted-foreground"> |
| 14 | + Directly interact with the Universal Bridge API from your backend, |
| 15 | + using standard REST api. |
| 16 | + </p> |
| 17 | + |
| 18 | + <div className="flex flex-col gap-8"> |
| 19 | + <BlueprintSection |
| 20 | + title="Available endpoints" |
| 21 | + blueprints={paths.map(([pathName, pathObj]) => { |
| 22 | + if (!pathObj) { |
| 23 | + throw new Error(`Path not found: ${pathName}`); |
| 24 | + } |
| 25 | + return { |
| 26 | + name: pathName, |
| 27 | + description: pathObj.get?.description || "", |
| 28 | + link: `/connect/pay/backend/reference?route=${pathName}`, |
| 29 | + }; |
| 30 | + })} |
| 31 | + /> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + ); |
| 35 | + } catch (error) { |
| 36 | + console.error(error); |
| 37 | + return <div>Error fetching API spec</div>; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +function BlueprintSection(props: { |
| 42 | + title: string; |
| 43 | + blueprints: { name: string; description: string; link: string }[]; |
| 44 | +}) { |
| 45 | + return ( |
| 46 | + <div className="overflow-hidden rounded-lg border bg-card"> |
| 47 | + <div className="flex items-center gap-2 border-b bg-accent/20 px-6 py-4"> |
| 48 | + <h2 className="font-semibold text-lg tracking-tight">{props.title}</h2> |
| 49 | + </div> |
| 50 | + <Table> |
| 51 | + <TableBody> |
| 52 | + {props.blueprints.map((item) => ( |
| 53 | + <TableRow |
| 54 | + key={item.link} |
| 55 | + className="group hover:bg-accent/50" |
| 56 | + linkBox |
| 57 | + > |
| 58 | + <TableCell> |
| 59 | + <span className="flex items-center gap-3"> |
| 60 | + <Link |
| 61 | + href={item.link} |
| 62 | + className="before:absolute before:inset-0" |
| 63 | + > |
| 64 | + <div className="flex flex-col"> |
| 65 | + <p className="text-md font-semibold">{item.name}</p> |
| 66 | + <p className="text-sm text-muted-foreground"> |
| 67 | + {item.description} |
| 68 | + </p> |
| 69 | + </div> |
| 70 | + </Link> |
| 71 | + </span> |
| 72 | + </TableCell> |
| 73 | + </TableRow> |
| 74 | + ))} |
| 75 | + </TableBody> |
| 76 | + </Table> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +} |
0 commit comments