diff --git a/src/pages/issuer/tabs/schemas.tsx b/src/pages/issuer/tabs/schemas.tsx index f0c1d3a..b494ad6 100644 --- a/src/pages/issuer/tabs/schemas.tsx +++ b/src/pages/issuer/tabs/schemas.tsx @@ -1,6 +1,7 @@ import { useState, useEffect } from "react" -import { getSchemas } from "../../../utils" +import { getSchemas, addSchema } from "../../../utils" import { DataGrid, GridColDef } from '@mui/x-data-grid'; +import { TextField, Button } from "@mui/material" const columns: GridColDef[] = [ @@ -9,16 +10,26 @@ const columns: GridColDef[] = [ ]; export function SchemasTab() { - const [schemas, setSchemas] = useState([]) + const [schemas, setSchemas] = useState([]); + const [newSchema, setNewSchema] = useState(""); const fetchData = async () => { const res = await getSchemas() setSchemas(res.map(x => atob(x))) } + const handleChange = (event: React.ChangeEvent) => { + setNewSchema(event.target.value); + } + + const applyAddSchema = () => { + addSchema(btoa(newSchema)).then(() => { fetchData(); }) + } + useEffect(() => { fetchData() }, []) return ( + <>
({ id: i, schema: x }))} @@ -32,5 +43,23 @@ export function SchemasTab() { checkboxSelection />
- ); +
+

Add new schema

+ + + + ); } \ No newline at end of file diff --git a/src/utils/api.ts b/src/utils/api.ts index b22a861..7938527 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -26,6 +26,17 @@ export async function getSchemas(): Promise { return result.filter(x => x.slice(0, 4) != "test") } +export async function addSchema(schema: string): Promise { + return (await fetch(`${getBackendUrl()}/issuer/schemas`, { + method: "POST", + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ schema, }) + })).json() +} + export async function getCredentials(userId: number): Promise { return (await fetch(`${getBackendUrl()}/issuer/credentials/${userId}`)).json() }