From 5efddef9372e44d6746b00abfcdaca902410396c Mon Sep 17 00:00:00 2001 From: Siddharth Date: Sun, 5 Nov 2023 13:02:05 +0530 Subject: [PATCH] feat: ux changes rebase --- apps/dashboard/app/callback/page.tsx | 53 +++++--- .../components/callback/callback-delete.tsx | 84 +++++++++--- .../components/callback/callback-input.tsx | 43 +++--- .../components/callback/callback-item.tsx | 123 ++++++++++-------- .../components/callback/callback-list.tsx | 64 +++++++++ .../graphql/queries/callback-query.ts | 4 +- 6 files changed, 266 insertions(+), 105 deletions(-) create mode 100644 apps/dashboard/components/callback/callback-list.tsx diff --git a/apps/dashboard/app/callback/page.tsx b/apps/dashboard/app/callback/page.tsx index 19b426d83c6..8fbc6790295 100644 --- a/apps/dashboard/app/callback/page.tsx +++ b/apps/dashboard/app/callback/page.tsx @@ -1,12 +1,16 @@ import { getServerSession } from "next-auth" import React from "react" +import { Box } from "@mui/joy" + import { authOptions } from "../api/auth/[...nextauth]/route" import ContentContainer from "@/components/content-container" -import { fetchCallbackData } from "@/services/graphql/queries/callback-query" -import CallbackItem from "@/components/callback/callback-item" +import CallBackList from "@/components/callback/callback-list" + import CreateCallBack from "@/components/callback/callback-input" +import { fetchCallbackData } from "@/services/graphql/queries/callback-query" +import CallBackCardItem from "@/components/callback/callback-item" export default async function page() { const session = await getServerSession(authOptions) @@ -14,27 +18,46 @@ export default async function page() { if (!token || typeof token !== "string") { throw new Error("invalid token") } - let response try { response = await fetchCallbackData(token) - } catch { + } catch (err) { return null } - const callbackEndpoints = response.data.me?.defaultAccount.callbackEndpoints || [] + const endpoints = response.data.me?.defaultAccount.callbackEndpoints || [] + return ( - - {callbackEndpoints.map((endpointItem) => { - return ( - - ) - })} + + + + + + + + + ) } diff --git a/apps/dashboard/components/callback/callback-delete.tsx b/apps/dashboard/components/callback/callback-delete.tsx index 54039560425..12bdecfe47e 100644 --- a/apps/dashboard/components/callback/callback-delete.tsx +++ b/apps/dashboard/components/callback/callback-delete.tsx @@ -1,11 +1,9 @@ "use client" import { useState } from "react" -import Button from "@mui/joy/Button" -import Modal from "@mui/joy/Modal" -import ModalClose from "@mui/joy/ModalClose" -import Typography from "@mui/joy/Typography" -import Sheet from "@mui/joy/Sheet" +import { Button, Typography, Box, Modal, Sheet, ModalClose } from "@mui/joy" + import DeleteIcon from "@mui/icons-material/Delete" +import ReportProblemRoundedIcon from "@mui/icons-material/ReportProblemRounded" import { deleteCallbackAction } from "@/app/callback/server-actions" @@ -15,13 +13,17 @@ type CallbackDeleteProps = { function DeleteCallback({ id }: CallbackDeleteProps) { const [open, setOpen] = useState(false) + const [loading, setLoading] = useState(false) const deleteHandler = async () => { try { + setLoading(true) await deleteCallbackAction(id) setOpen(false) } catch (error) { console.error(error) + } finally { + setLoading(false) } } @@ -35,33 +37,75 @@ function DeleteCallback({ id }: CallbackDeleteProps) { - - + - Delete Callback + + + Delete Callback + + + + Are you sure you want to delete? You will not be able to use this callback + further. - Are you sure you want to delete? - + - setOpen(true)}> + + + ) } diff --git a/apps/dashboard/components/callback/callback-input.tsx b/apps/dashboard/components/callback/callback-input.tsx index 603c289172b..e2ab8693bd1 100644 --- a/apps/dashboard/components/callback/callback-input.tsx +++ b/apps/dashboard/components/callback/callback-input.tsx @@ -2,6 +2,7 @@ import Button from "@mui/joy/Button" import { Input, FormLabel, FormControl, FormHelperText } from "@mui/joy" import Modal from "@mui/joy/Modal" +import Box from "@mui/joy/Box" import ModalClose from "@mui/joy/ModalClose" import Typography from "@mui/joy/Typography" import Sheet from "@mui/joy/Sheet" @@ -18,6 +19,8 @@ import { experimental_useFormState as useFormState, } from "react-dom" +import FormSubmitButton from "../form-submit-button" + import { createCallbackAction } from "@/app/callback/server-actions" function CreateCallBack() { @@ -30,7 +33,9 @@ function CreateCallBack() { }) if (state.message === "success") { + state.error = false state.message = null + state.responsePayload = null setOpen(false) } return ( @@ -43,15 +48,15 @@ function CreateCallBack() { @@ -73,9 +78,15 @@ function CreateCallBack() { gap: "1em", justifyContent: "center", alignItems: "center", + width: "100%", }} > - + Callback URL ) : null} - + - + + Attach Callback Endpoints + + + ) } diff --git a/apps/dashboard/components/callback/callback-item.tsx b/apps/dashboard/components/callback/callback-item.tsx index 5c9c0e4fd53..951f57e0814 100644 --- a/apps/dashboard/components/callback/callback-item.tsx +++ b/apps/dashboard/components/callback/callback-item.tsx @@ -1,66 +1,85 @@ -"use client" import React from "react" - -import { Box, Card, Typography } from "@mui/joy" +import { Card, Typography, Box } from "@mui/joy" import DeleteCallback from "./callback-delete" -type CallbackEndpointProps = { - id: string - url: string +type EndPointProps = { + readonly id: string + readonly url: string +} + +type EndPointCardListProps = { + endpoints: readonly EndPointProps[] } -function callbackItem({ id, url }: CallbackEndpointProps) { +const CallBackCardItem = ({ endpoints }: EndPointCardListProps) => { return ( - - - + {endpoints.map(({ id, url }) => ( + - {id} - + + ID + + {id} + + - - {url} - - - - + + URL + + {url} + + + + + + ))} + {endpoints.length === 0 && No Callbacks Added} + ) } -export default callbackItem +export default CallBackCardItem diff --git a/apps/dashboard/components/callback/callback-list.tsx b/apps/dashboard/components/callback/callback-list.tsx new file mode 100644 index 00000000000..306e233555f --- /dev/null +++ b/apps/dashboard/components/callback/callback-list.tsx @@ -0,0 +1,64 @@ +import React from "react" +import Table from "@mui/joy/Table" + +import { Typography } from "@mui/joy" + +import DeleteCallback from "./callback-delete" + +type EndPointProps = { + readonly id: string + readonly url: string +} + +type EndPointCardListProps = { + endpoints: readonly EndPointProps[] +} + +const CallBackList = async ({ endpoints }: EndPointCardListProps) => { + return ( + <> + + + + + + + + + + {endpoints.map(({ id, url }) => ( + + + + + + ))} + +
+ ID + + Endpoint URL + + Action +
{id}{url} + +
+ {endpoints.length === 0 && No Callbacks Added} + + ) +} + +export default CallBackList diff --git a/apps/dashboard/services/graphql/queries/callback-query.ts b/apps/dashboard/services/graphql/queries/callback-query.ts index c1695627404..e6644ff01fe 100644 --- a/apps/dashboard/services/graphql/queries/callback-query.ts +++ b/apps/dashboard/services/graphql/queries/callback-query.ts @@ -19,10 +19,10 @@ gql` export async function fetchCallbackData(token: string) { const client = apollo(token).getClient() try { - const data = await client.query({ + const response = await client.query({ query: CallbackEndpointsDocument, }) - return data + return response } catch (err) { if (err instanceof Error) { console.error("error", err)