Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | import { useState, useCallback } from 'react';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import AiIcon from '@mui/icons-material/AutoAwesome';
import { FieldAIAssistDialog } from './FieldAIAssistDialog';
interface FieldAIAssistButtonProps {
fieldKey: string;
fieldType: string;
fieldContent: string;
availableTemplates: string[];
onReplace: (content: string) => void;
onAppend: (content: string) => void;
siteKey: string;
workspaceKey: string;
collectionKey?: string;
collectionItemKey?: string;
singleKey?: string;
}
export function FieldAIAssistButton({
fieldKey,
fieldType,
fieldContent,
availableTemplates,
onReplace,
onAppend,
siteKey,
workspaceKey,
collectionKey,
collectionItemKey,
singleKey,
}: FieldAIAssistButtonProps) {
const [dialogOpen, setDialogOpen] = useState(false);
const handleOpen = useCallback(() => {
setDialogOpen(true);
}, []);
const handleClose = useCallback(() => {
setDialogOpen(false);
}, []);
// Don't render if no templates available
if (!availableTemplates || availableTemplates.length === 0) {
return null;
}
return (
<>
<Tooltip title="Field Assist">
<IconButton aria-label="Page Assist" onClick={handleOpen} size="small">
<AiIcon />
</IconButton>
</Tooltip>
<FieldAIAssistDialog
open={dialogOpen}
onClose={handleClose}
siteKey={siteKey}
workspaceKey={workspaceKey}
fieldKey={fieldKey}
fieldType={fieldType}
fieldContent={fieldContent}
availableTemplates={availableTemplates}
onReplace={onReplace}
onAppend={onAppend}
collectionKey={collectionKey}
collectionItemKey={collectionItemKey}
singleKey={singleKey}
/>
</>
);
}
export default FieldAIAssistButton;
|