import CardBox from '../CardBox'; import { mdiCog } from '@mdi/js'; import { Field, Form, Formik } from 'formik'; import { ToastContainer, toast } from 'react-toastify'; import FormField from '../FormField'; import React from 'react'; import { aiPrompt, setErrorNotification, resetNotify, } from '../../stores/openAiSlice'; import { useAppDispatch, useAppSelector } from '../../stores/hooks'; import { fetchWidgets } from '../../stores/roles/rolesSlice'; import BaseButton from '../BaseButton'; import CardBoxModal from '../CardBoxModal'; import { RoleSelect } from './RoleSelect'; export const WidgetCreator = ({ currentUser, isFetchingQuery, setWidgetsRole, widgetsRole, }) => { const dispatch = useAppDispatch(); const [isModalOpen, setIsModalOpen] = React.useState(false); const { notify: openAiNotify } = useAppSelector((state) => state.openAi); const notify = (type, msg) => toast(msg, { type, position: 'bottom-center' }); React.useEffect(() => { if (openAiNotify.showNotification) { notify(openAiNotify.typeNotification, openAiNotify.textNotification); dispatch(resetNotify()); } }, [openAiNotify.showNotification]); const openModal = (): void => { setIsModalOpen(true); }; const handleCloseModal = (value = {}) => { setWidgetsRole(value); setIsModalOpen(false); }; const getWidgets = async () => { await dispatch(fetchWidgets(widgetsRole?.role?.value || '')); }; const smartSearch = async ( values: { description: string }, resetForm: any, ) => { const description = values.description; const projectId = '29665'; const payload = { roleId: widgetsRole?.role?.value, description, projectId, userId: currentUser?.id, }; const { payload: responcePayload, error }: any = await dispatch( aiPrompt(payload), ); await getWidgets().then(); resetForm({ values: { description: '' } }); if (responcePayload.data?.error || error) { const errorMessage = responcePayload.data?.error?.message || error?.message; await dispatch( setErrorNotification(errorMessage || 'Error with widget creation'), ); } }; return ( <> smartSearch(values, resetForm)} > handleCloseModal(values)} > {({ submitForm }) => ( setIsModalOpen(false)} > What role are we showing and creating widgets for? )} > ); };
What role are we showing and creating widgets for?