Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback API structure #43

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ const useFeedbacks = (): IFeedbackType[] => {
{
title: t("general.too_bad"),
imageSrc: "/images/faces/very_bad.svg",
level: 0,
level: 1,
},
{
title: t("general.bad"),
imageSrc: "/images/faces/very_bad.svg",
level: 1,
level: 2,
},
{
title: t("general.not_bad"),
imageSrc: "/images/faces/not_bad.svg",
level: 2,
level: 3,
},
{
title: t("general.good"),
imageSrc: "/images/faces/good.svg",
level: 3,
level: 4,
},
{
title: t("general.very_good"),
imageSrc: "/images/faces/very_good.svg",
level: 4,
level: 5,
},
];
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useFeedbacksConstants, {
type IFeedbackType,
} from "./Feedback.constants";
import { usePostFeedBackMutation } from "@/store/feedback/api";
import {
Button,
Popover,
Expand All @@ -21,6 +22,15 @@ const Feedback = () => {
const { t } = useTranslation();
const [active, setActive] = useState();
const feedbacks = useFeedbacksConstants();
const [inputValue, setInputValue] = useState<string>("");
const [FeedBack, { status, isLoading, data }] = usePostFeedBackMutation();

const handleSubmitFeedback = () => {
void FeedBack({
description: inputValue,
rate: active,
});
};

return (
<Popover>
Expand All @@ -35,6 +45,7 @@ const Feedback = () => {
id="width"
placeholder={t("feedback.placeholder")}
className="col-span-2 h-8"
onChange={(e) => setInputValue(e.target.value)}
/>
</div>
</div>
Expand All @@ -48,7 +59,9 @@ const Feedback = () => {
/>
))}
</div>
<Button>{t("feedback.submit")}</Button>
<Button onClick={() => handleSubmitFeedback()}>
{t("feedback.submit")}
</Button>
</div>
</PopoverContent>
</Popover>
Expand Down
57 changes: 46 additions & 11 deletions apps/next/src/components/Modals/CopyWords/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { WordPage } from "../../Translate/word.constant";
import CButton from "@/components/UI/Button";
import { useCreateWordMutation, useGetDictionaryWordsMutation } from "@/store/dictionarayWord/api";
import CreateDictionary from "../CreateDictionaries";
import {
useCreateWordMutation,
useGetDictionaryWordsMutation,
} from "@/store/dictionarayWord/api";
import { zodResolver } from "@hookform/resolvers/zod";
import { Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Form, FormControl, FormField, FormItem, FormMessage, Input, Label, useToast, SelectTrigger, Select, SelectValue, SelectContent, SelectItem } from "@wordigo/ui";
import {
Button,
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
Label,
useToast,
SelectTrigger,
Select,
SelectValue,
SelectContent,
SelectItem,
} from "@wordigo/ui";
import { cn } from "@wordigo/ui/lib/utils";
import { Table2Icon, X } from "lucide-react";
import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import CreateDictionary from "../CreateDictionaries";

const CreateWordSchema = z.object({
text: z.string().nonempty(),
Expand All @@ -22,7 +37,15 @@ const CreateWordSchema = z.object({

type CreateWordValues = z.infer<typeof CreateWordSchema>;

export function CopyWord({ label, className, isHaveData }: { label: string | null, className?: React.ReactNode, isHaveData: any }) {
export function CopyWord({
label,
className,
isHaveData,
}: {
label: string | null;
className?: React.ReactNode;
isHaveData: any;
}) {
const [open, setOpen] = useState(false);
const { toast } = useToast();
const { t } = useTranslation();
Expand All @@ -44,7 +67,8 @@ export function CopyWord({ label, className, isHaveData }: { label: string | nul
defaultValues,
});

const [addUserDicWords, { status, isLoading, data }] = useCreateWordMutation();
const [addUserDicWords, { status, isLoading, data }] =
useCreateWordMutation();

const handleAddWord = (values: CreateWordValues) => {
void addUserDicWords({
Expand Down Expand Up @@ -83,7 +107,14 @@ export function CopyWord({ label, className, isHaveData }: { label: string | nul
return (
<Dialog open={open}>
<DialogTrigger asChild>
<Button onClick={toggleShow} variant="outline" className={cn("dark:bg-white dark:text-black bg-black text-white font-semibold text-sm", className)}>
<Button
onClick={toggleShow}
variant="outline"
className={cn(
"dark:bg-white dark:text-black bg-black text-white font-semibold text-sm",
className
)}
>
{t(label)}
</Button>
</DialogTrigger>
Expand All @@ -102,7 +133,9 @@ export function CopyWord({ label, className, isHaveData }: { label: string | nul
</button>
</DialogHeader>
<Select>
<Label htmlFor="selectDictionaries" className="-mb-2">Dictionaries</Label>
<Label htmlFor="selectDictionaries" className="-mb-2">
Dictionaries
</Label>
<SelectTrigger className="w-full h-[40px] px-4">
<SelectValue placeholder="Dictionaries" />
</SelectTrigger>
Expand All @@ -113,8 +146,10 @@ export function CopyWord({ label, className, isHaveData }: { label: string | nul
</SelectContent>
</Select>
<div className="flex items-center justify-between">
<CreateDictionary label={"dictionaries.add_dictionaries"}></CreateDictionary>
<Button>{t('save')}</Button>
<CreateDictionary
label={"dictionaries.add_dictionaries"}
></CreateDictionary>
<Button>{t("save")}</Button>
</div>
</DialogContent>
</Dialog>
Expand Down
20 changes: 20 additions & 0 deletions apps/next/src/store/feedback/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { axiosBaseQuery } from "../baseQuery";
import { createApi } from "@reduxjs/toolkit/query/react";

export const feedbackApi = createApi({
reducerPath: "feedbackApi",
baseQuery: axiosBaseQuery({
baseUrl: process.env.NEXT_PUBLIC_WORDIGO_BACKEND_URL,
}),
endpoints: (builder) => ({
postFeedBack: builder.mutation<any, any>({
query: (data) => ({
url: "/general/feedback",
data,
method: "post",
}),
}),
}),
});

export const { usePostFeedBackMutation } = feedbackApi;
32 changes: 32 additions & 0 deletions apps/next/src/store/feedback/slice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { feedbackApi } from "./api";
import { type FeedBack } from "./type";
import { createSlice } from "@reduxjs/toolkit";

interface IWordState {
feedback: any;
}

const initialState: IWordState = {
feedback: null,
} as IWordState;

const feedbackSlice = createSlice({
name: "FeedBack",
initialState,
reducers: {
setFeedback(state, action) {
state.feedback = action.payload;
},
},
extraReducers: (builder) => {
builder.addMatcher(
feedbackApi.endpoints.postFeedBack.matchFulfilled,
(state, action: any) => {
state.feedback = action.payload.data;
}
);
},
});

export default feedbackSlice.reducer;
export const { setFeedback } = feedbackSlice.actions;
4 changes: 4 additions & 0 deletions apps/next/src/store/feedback/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface FeedBack {
description: string;
rate: 5;
}
Loading