Skip to content

Commit

Permalink
Open ai slice implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
NishantCoder108 committed Mar 3, 2024
1 parent 8a1fce2 commit f759041
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app/store.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { configureStore } from "@reduxjs/toolkit";
import authReducer from "../features/authSlice";
import bookReducer from "../features/bookSlice";
import aiCredentialReducer from "../features/aiCredentialSlice";

export const store = configureStore({
reducer: {
auth: authReducer,
books: bookReducer,
aiCredential: aiCredentialReducer,
},
devTools: process.env.NODE_ENV !== "production",
});
Expand Down
12 changes: 11 additions & 1 deletion src/components/CredentilsFormForAi.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { Button, Input } from "@nextui-org/react";
import { useForm } from "react-hook-form";
import { useAppDispatch } from "../app/hooks";
import { addAiCredential } from "../features/aiCredentialSlice";

interface ICredentialsForAi {
openAiKey: string;
}
const CredentilsFormForAi = () => {
interface IProps {
onClose: () => void;
}
const CredentilsFormForAi = ({ onClose }: IProps) => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<ICredentialsForAi>();

const dispatch = useAppDispatch();

const handleFormSubmit = handleSubmit((data) => {
console.log("Credential Form Data", data);
const trimData = data.openAiKey.trim();
dispatch(addAiCredential(trimData));
onClose();
});

console.log(errors);
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchByAi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SearchByAi = () => {
return (
<div>
<AppModal
modalBody={<CredentilsFormForAi />}
modalBody={<CredentilsFormForAi onClose={onClose} />}
title={"Integrate Your App With Ai"}
isOpen={isOpen}
onClose={onClose}
Expand Down
18 changes: 18 additions & 0 deletions src/features/aiCredentialSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createSlice } from "@reduxjs/toolkit";

const openAiKey: string | null = null;

export const aiCredentialSlice = createSlice({
name: "aiCredential",
initialState: openAiKey,
reducers: {
addAiCredential: (_, action) => {
return action.payload;
},
},
});

// Action creators are generated for each case reducer function
export const { addAiCredential } = aiCredentialSlice.actions;

export default aiCredentialSlice.reducer;

0 comments on commit f759041

Please sign in to comment.