Skip to content

Commit

Permalink
feat: Add example of getting detailed feeback info
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed May 17, 2024
1 parent 8fbe1d6 commit 7f48039
Showing 1 changed file with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,65 @@
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import gql from "graphql-tag";
import { client } from "lib/graphql";
import React from "react";
import { Feedback } from "routes/feedback";

interface Props {
feedback: Feedback[];
}

const GET_FEEDBACK_BY_ID_QUERY = gql`
query GetFeedbackById($feedbackId: Int!) {
feedback: feedback_summary(where: { feedback_id: { _eq: $feedbackId } }) {
address
createdAt: created_at
device
feedbackId: feedback_id
feedbackType: feedback_type
helpDefinition: help_definition
helpSources: help_sources
helpText: help_text
intersectingConstraints: intersecting_constraints
nodeData: node_data
nodeId: node_id
nodeText: node_text
nodeTitle: node_title
nodeType: node_type
projectType: project_type
serviceSlug: service_slug
teamSlug: team_slug
status
uprn
userComment: user_comment
userContext: user_context
}
}
`;

const getDetailedFeedback = async (feedbackId: number) => {
const {
data: {
feedback: [detailedFeedback],
},
} = await client.query({
query: GET_FEEDBACK_BY_ID_QUERY,
variables: { feedbackId },
});
console.log(detailedFeedback);
};

export const FeedbackPage: React.FC<Props> = ({ feedback }) => {
return (
<Box component="pre" sx={{ fontSize: 12, overflowY: "auto" }}>
{JSON.stringify(feedback, null, 4)}
<Box sx={{ fontSize: 12, overflowY: "auto" }}>
{feedback.map((item) => (
<React.Fragment key={item.id}>
<Box component="pre">{JSON.stringify(item, null, 4)}</Box>
<Button onClick={() => getDetailedFeedback(item.id)}>
Log out detailed info
</Button>
</React.Fragment>
))}
</Box>
);
};

0 comments on commit 7f48039

Please sign in to comment.