import { ActiveState } from '../models/misc'; import Input from '../components/Input'; import React from 'react'; import { useTranslation } from 'react-i18next'; import WrapperModal from '../modals/WrapperModal'; function AddPrompt({ setModalState, handleAddPrompt, newPromptName, setNewPromptName, newPromptContent, setNewPromptContent, disableSave, }: { setModalState: (state: ActiveState) => void; handleAddPrompt?: () => void; newPromptName: string; setNewPromptName: (name: string) => void; newPromptContent: string; setNewPromptContent: (content: string) => void; disableSave: boolean; }) { const { t } = useTranslation(); return (

{t('modals.prompts.addPrompt')}

{t('modals.prompts.addDescription')}

setNewPromptName(e.target.value)} />
{t('modals.prompts.promptText')}
); } function EditPrompt({ setModalState, handleEditPrompt, editPromptName, setEditPromptName, editPromptContent, setEditPromptContent, currentPromptEdit, disableSave, }: { setModalState: (state: ActiveState) => void; handleEditPrompt?: (id: string, type: string) => void; editPromptName: string; setEditPromptName: (name: string) => void; editPromptContent: string; setEditPromptContent: (content: string) => void; currentPromptEdit: { name: string; id: string; type: string }; disableSave: boolean; }) { const { t } = useTranslation(); return (

{t('modals.prompts.editPrompt')}

{t('modals.prompts.editDescription')}

setEditPromptName(e.target.value)} />
{t('modals.prompts.promptName')}
{t('modals.prompts.promptText')}
); } export default function PromptsModal({ existingPrompts, modalState, setModalState, type, newPromptName, setNewPromptName, newPromptContent, setNewPromptContent, editPromptName, setEditPromptName, editPromptContent, setEditPromptContent, currentPromptEdit, handleAddPrompt, handleEditPrompt, }: { existingPrompts: { name: string; id: string; type: string }[]; modalState: ActiveState; setModalState: (state: ActiveState) => void; type: 'ADD' | 'EDIT'; newPromptName: string; setNewPromptName: (name: string) => void; newPromptContent: string; setNewPromptContent: (content: string) => void; editPromptName: string; setEditPromptName: (name: string) => void; editPromptContent: string; setEditPromptContent: (content: string) => void; currentPromptEdit: { name: string; id: string; type: string }; handleAddPrompt?: () => void; handleEditPrompt?: (id: string, type: string) => void; }) { const [disableSave, setDisableSave] = React.useState(true); const handlePrompNameChange = (edit: boolean, newName: string) => { const nameExists = existingPrompts.find( (prompt) => newName === prompt.name, ); if (newName && !nameExists) { setDisableSave(false); } else { setDisableSave(true); } if (edit) { setEditPromptName(newName); } else { setNewPromptName(newName); } }; let view; if (type === 'ADD') { view = ( ); } else if (type === 'EDIT') { view = ( ); } else { view = <>; } return modalState === 'ACTIVE' ? ( { setModalState('INACTIVE'); if (type === 'ADD') { setNewPromptName(''); setNewPromptContent(''); } }} className="sm:w-[512px] mt-24" > {view} ) : null; }