-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support report and preview feedback
- Loading branch information
Showing
12 changed files
with
288 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Table, TableContainer, Tbody, Td, Th, Thead, Tr } from '@chakra-ui/react' | ||
import dayjs from 'dayjs' | ||
import type { FC } from 'react' | ||
import type { Feedback } from '@prisma/client' | ||
import { renderStringOrJson } from '~/libs/utils' | ||
|
||
interface Props { | ||
feedbacks?: Feedback[] | ||
} | ||
|
||
const FeedbacksList: FC<Props> = ({ feedbacks }) => { | ||
return ( | ||
<TableContainer> | ||
<Table className="w-full table table-compact"> | ||
<Thead> | ||
<Tr> | ||
<Th>createdAt</Th> | ||
<Th>feedback</Th> | ||
<Th>user</Th> | ||
<Th>selected element</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{ | ||
feedbacks?.map((feedback) => { | ||
const detail = feedback.detail as any | ||
return ( | ||
<Tr key={feedback.id}> | ||
<Td> | ||
{dayjs(feedback.createdAt).format('YYYY-MM-DD HH:mm:ss')} | ||
</Td> | ||
<Td>{detail.feedback}</Td> | ||
<Td>{renderStringOrJson(feedback.user)}</Td> | ||
<Td> | ||
<img | ||
alt="selected element" | ||
src={detail.dataURL} | ||
/> | ||
</Td> | ||
</Tr> | ||
) | ||
}) | ||
} | ||
</Tbody> | ||
</Table> | ||
</TableContainer> | ||
) | ||
} | ||
|
||
export default FeedbacksList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Button } from '@chakra-ui/react' | ||
import type { Feedback } from '@prisma/client' | ||
import type { NextPage } from 'next' | ||
import { useTranslations } from 'next-intl' | ||
import FeedbacksList from '~/components/feedbacksList' | ||
import ThemeBox from '~/components/themeBox' | ||
import Title from '~/components/title' | ||
import Wrapper from '~/components/wrapper' | ||
import useCurrentProject from '~/hooks/useCurrentProject' | ||
import { useInfinite } from '~/hooks/useInfinite' | ||
|
||
const Feedbacks: NextPage = () => { | ||
const ct = useTranslations('Common') | ||
const { projectId } = useCurrentProject() | ||
const { data: feedbacks, isLoading, size, setSize, isReachingEnd } = useInfinite<Feedback>(index => `/api/feedbacks?projectId=${projectId}&page=${index + 1}`) | ||
|
||
return ( | ||
<ThemeBox bg="current"> | ||
<Title> | ||
Feedbacks | ||
</Title> | ||
|
||
<Wrapper> | ||
<FeedbacksList feedbacks={feedbacks} /> | ||
<Button | ||
disabled={isLoading || isReachingEnd} | ||
mt="6" | ||
onClick={() => setSize(size + 1)} | ||
size="sm" | ||
variant="outline" | ||
w="full" | ||
> | ||
{ | ||
isLoading | ||
? `${ct('loading')}...` | ||
: isReachingEnd | ||
? ct('noMoreData') | ||
: ct('loadMore') | ||
} | ||
</Button> | ||
</Wrapper> | ||
</ThemeBox> | ||
) | ||
} | ||
|
||
export default Feedbacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import type { Feedback } from '@prisma/client' | ||
import { getAuth } from '~/libs/middleware' | ||
import { serviceGetFeedback } from '~/services/feedbacks' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<Feedback>, | ||
) { | ||
const auth = await getAuth(req, res) | ||
if (!auth) return | ||
|
||
const feedback = await serviceGetFeedback({ id: req.query.id as string }) | ||
if (feedback) { res.status(200).json(feedback) } | ||
else { res.end(`Feedback ${req.query.id} not found`) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import type { Feedback } from '@prisma/client' | ||
import { PAGE_SIZE } from 'common' | ||
import { serviceGetFeedbacks } from '~/services/feedbacks' | ||
import { getAuth } from '~/libs/middleware' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<Feedback[]>, | ||
) { | ||
const auth = await getAuth(req, res) | ||
if (!auth) return | ||
|
||
const page = parseInt(req.query.page as string) || 1 | ||
const pageSize = parseInt(req.query.pageSize as string) || PAGE_SIZE | ||
const projectId = parseInt(req.query.projectId as string) | ||
const query = req.query.query as string | ||
const feedbacks = await serviceGetFeedbacks({ | ||
page, | ||
pageSize, | ||
projectId, | ||
query, | ||
}) | ||
res.status(200).json(feedbacks) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Pagination } from 'common' | ||
import { PAGE_SIZE, pagination } from 'common' | ||
import { serviceGetProject } from './projects' | ||
import { getPrisma } from '~/db' | ||
|
||
interface ServiceGetFeedbacksParams extends Pagination { | ||
projectId: number | ||
query?: string | ||
} | ||
export async function serviceGetFeedbacks({ | ||
projectId, | ||
query, | ||
page = 0, | ||
pageSize = PAGE_SIZE, | ||
}: ServiceGetFeedbacksParams) { | ||
const project = await serviceGetProject(projectId) | ||
const options: any = { | ||
where: { apiKey: project.apiKey }, | ||
...pagination({ page, pageSize }), | ||
} | ||
if (query) { | ||
options.where.metadata = { search: query } | ||
} | ||
return getPrisma().feedback.findMany(options) | ||
} | ||
|
||
interface ServiceGetFeedbackParams { | ||
id: string | ||
} | ||
export function serviceGetFeedback({ id }: ServiceGetFeedbackParams) { | ||
return getPrisma().feedback.findUniqueOrThrow({ where: { id } }) | ||
} |
26 changes: 26 additions & 0 deletions
26
prisma/migrations/20220803074940_add_feedback_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- CreateTable | ||
CREATE TABLE "Feedback" ( | ||
"id" TEXT NOT NULL, | ||
"apiKey" TEXT NOT NULL, | ||
"appVersion" TEXT, | ||
"appType" TEXT, | ||
"releaseStage" TEXT, | ||
"timestamp" TIMESTAMP(3) NOT NULL, | ||
"category" TEXT, | ||
"type" TEXT NOT NULL, | ||
"sdk" JSONB NOT NULL, | ||
"detail" JSONB NOT NULL, | ||
"device" JSONB NOT NULL, | ||
"user" JSONB, | ||
"actions" JSONB, | ||
"metadata" JSONB, | ||
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "Feedback_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "Feedback_apiKey_idx" ON "Feedback"("apiKey"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "Feedback_createdAt_idx" ON "Feedback" USING BRIN ("createdAt" timestamp_bloom_ops); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters