Commit e19bc8d3 by Arjun Jhukal

updated the dynamic provider at game addition

parent d989428f
...@@ -4,8 +4,9 @@ import { InputLabel } from "@mui/material"; ...@@ -4,8 +4,9 @@ import { InputLabel } from "@mui/material";
import React from "react"; import React from "react";
interface Option { interface Option {
id?: number | string
value: string; value: string;
label: string; name: string;
} }
interface SelectFieldProps { interface SelectFieldProps {
...@@ -47,7 +48,7 @@ export default function SelectField({ ...@@ -47,7 +48,7 @@ export default function SelectField({
<option value="">Select the Type of Game</option> <option value="">Select the Type of Game</option>
{options.map((option) => ( {options.map((option) => (
<option key={option.value} value={option.value}> <option key={option.value} value={option.value}>
{option.label} {option.name}
</option> </option>
))} ))}
</select> </select>
......
...@@ -4,9 +4,10 @@ import SelectField from "@/components/atom/SelectField"; ...@@ -4,9 +4,10 @@ import SelectField from "@/components/atom/SelectField";
import ReactQuillEditor from "@/components/molecules/ReactQuill"; import ReactQuillEditor from "@/components/molecules/ReactQuill";
import { useAppDispatch } from "@/hooks/hook"; import { useAppDispatch } from "@/hooks/hook";
import { useAddGameMutation } from "@/services/gameApi"; import { useAddGameMutation } from "@/services/gameApi";
import { useGetAllProviderQuery } from "@/services/providerApi";
import { showToast, ToastVariant } from "@/slice/toastSlice"; import { showToast, ToastVariant } from "@/slice/toastSlice";
import { gameInitialValues, GameProps } from "@/types/game"; import { gameInitialValues, GameProps } from "@/types/game";
import { Button, InputLabel, Input } from "@mui/material"; import { Button, InputLabel, Input, OutlinedInput } from "@mui/material";
import { useFormik } from "formik"; import { useFormik } from "formik";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import * as Yup from "yup"; import * as Yup from "yup";
...@@ -27,9 +28,8 @@ const validationSchema = Yup.object({ ...@@ -27,9 +28,8 @@ const validationSchema = Yup.object({
export default function AddGameForm({ id }: AddGameFormProps) { export default function AddGameForm({ id }: AddGameFormProps) {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const router = useRouter(); const router = useRouter();
const { data: gameProviders, isLoading } = useGetAllProviderQuery();
const [addGame, { isLoading: addingGame }] = useAddGameMutation(); const [addGame, { isLoading: addingGame }] = useAddGameMutation();
const formik = useFormik<GameProps>({ const formik = useFormik<GameProps>({
initialValues: gameInitialValues, initialValues: gameInitialValues,
validationSchema, validationSchema,
...@@ -100,7 +100,7 @@ export default function AddGameForm({ id }: AddGameFormProps) { ...@@ -100,7 +100,7 @@ export default function AddGameForm({ id }: AddGameFormProps) {
{/* Name */} {/* Name */}
<div className="input__field"> <div className="input__field">
<InputLabel htmlFor="name">Name of the Game<span className="text-red-500">*</span></InputLabel> <InputLabel htmlFor="name">Name of the Game<span className="text-red-500">*</span></InputLabel>
<Input <OutlinedInput
fullWidth fullWidth
id="name" id="name"
name="name" name="name"
...@@ -138,9 +138,9 @@ export default function AddGameForm({ id }: AddGameFormProps) { ...@@ -138,9 +138,9 @@ export default function AddGameForm({ id }: AddGameFormProps) {
onBlur={() => formik.setFieldTouched("category", true)} onBlur={() => formik.setFieldTouched("category", true)}
required required
options={[ options={[
{ value: "action", label: "Action" }, { value: "action", name: "Action" },
{ value: "adventure", label: "Adventure" }, { value: "adventure", name: "Adventure" },
{ value: "puzzle", label: "Puzzle" }, { value: "puzzle", name: "Puzzle" },
]} ]}
/> />
<span className="error"> <span className="error">
...@@ -215,7 +215,7 @@ export default function AddGameForm({ id }: AddGameFormProps) { ...@@ -215,7 +215,7 @@ export default function AddGameForm({ id }: AddGameFormProps) {
{/* API */} {/* API */}
<div className="input__field"> <div className="input__field">
<InputLabel>API<span className="text-red-500">*</span></InputLabel> <InputLabel>API<span className="text-red-500">*</span></InputLabel>
<Input <OutlinedInput
fullWidth fullWidth
id="api" id="api"
name="api" name="api"
...@@ -238,11 +238,15 @@ export default function AddGameForm({ id }: AddGameFormProps) { ...@@ -238,11 +238,15 @@ export default function AddGameForm({ id }: AddGameFormProps) {
onChange={(e) => formik.setFieldValue("provider", e.target.value)} onChange={(e) => formik.setFieldValue("provider", e.target.value)}
onBlur={() => formik.setFieldTouched("provider", true)} onBlur={() => formik.setFieldTouched("provider", true)}
required={true} required={true}
options={[ options={
{ value: "provider1", label: "Provider 1" }, !isLoading && gameProviders
{ value: "provider2", label: "Provider 2" }, ? gameProviders.data.map((provider: any) => ({
{ value: "provider3", label: "Provider 3" }, id: provider.id,
]} value: provider.slug || provider.value, // choose what your API gives
name: provider.name,
}))
: []
}
/> />
<span className="error"> <span className="error">
{formik.touched.provider && formik.errors.provider ? formik.errors.provider : ""} {formik.touched.provider && formik.errors.provider ? formik.errors.provider : ""}
...@@ -252,7 +256,7 @@ export default function AddGameForm({ id }: AddGameFormProps) { ...@@ -252,7 +256,7 @@ export default function AddGameForm({ id }: AddGameFormProps) {
{/* Extra Thumbnail */} {/* Extra Thumbnail */}
<div className="input__field"> <div className="input__field">
<InputLabel htmlFor="profit">Profit % for Superadmin (you)<span className="text-red-500">*</span></InputLabel> <InputLabel htmlFor="profit">Profit % for Superadmin (you)<span className="text-red-500">*</span></InputLabel>
<Input <OutlinedInput
fullWidth fullWidth
id="profit" id="profit"
name="profit" name="profit"
......
...@@ -4,6 +4,7 @@ import auth from "@/slice/authSlice"; ...@@ -4,6 +4,7 @@ import auth from "@/slice/authSlice";
import toastSlice from "@/slice/toastSlice"; import toastSlice from "@/slice/toastSlice";
import { gameApi } from "@/services/gameApi"; import { gameApi } from "@/services/gameApi";
import { playerApi } from "@/services/playerApi"; import { playerApi } from "@/services/playerApi";
import { providerApi } from "@/services/providerApi";
export const store = configureStore({ export const store = configureStore({
reducer: { reducer: {
...@@ -11,6 +12,7 @@ export const store = configureStore({ ...@@ -11,6 +12,7 @@ export const store = configureStore({
toastSlice, toastSlice,
[authApi.reducerPath]: authApi.reducer, [authApi.reducerPath]: authApi.reducer,
[gameApi.reducerPath]: gameApi.reducer, [gameApi.reducerPath]: gameApi.reducer,
[providerApi.reducerPath]: providerApi.reducer,
[playerApi.reducerPath]: playerApi.reducer, [playerApi.reducerPath]: playerApi.reducer,
}, },
middleware: (getDefaultMiddleware) => middleware: (getDefaultMiddleware) =>
...@@ -18,6 +20,7 @@ export const store = configureStore({ ...@@ -18,6 +20,7 @@ export const store = configureStore({
.concat(authApi.middleware) .concat(authApi.middleware)
.concat(gameApi.middleware) .concat(gameApi.middleware)
.concat(playerApi.middleware) .concat(playerApi.middleware)
.concat(providerApi.middleware)
}) })
......
import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQuery } from "./baseQuery";
export const providerApi = createApi({
reducerPath: "providerApi",
baseQuery: baseQuery,
tagTypes: ["providers"],
endpoints: (builder) => ({
getAllProvider: builder.query<GameProviderResponseProps, void>({
query: () => ({
url: "/api/admin/game/providers",
method: "GET"
})
})
})
})
export const { useGetAllProviderQuery } = providerApi;
\ No newline at end of file
interface GameProviderResponseProps {
success: true,
data: {
id: 1,
name: string,
value: string
}[],
message: String
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment