Amitkasar's picture
solved issue
f1c3c6d
Raw History Blame
5.73 kB
import React, { useState } from 'react';
import { Layers, X, Code, KeyRound } from 'lucide-react';
export default function SelectionModal({ selectionPrompt, onSelect, onConfirm, onCancel }) {
const [inputValues, setInputValues] = useState({});
const type = selectionPrompt.type || 'selection';
const missingKeys = selectionPrompt.missingKeys || [];
const allFilled = missingKeys.every(k => inputValues[k]?.trim());
return (
<div style={{ position: 'fixed', inset: 0, zIndex: 50, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.7)', backdropFilter: 'blur(8px)', padding: 16 }}>
<div style={{ background: 'var(--bg-1)', border: '1px solid var(--line-3)', borderRadius: 10, width: '100%', maxWidth: 480, maxHeight: '80vh', overflow: 'hidden', display: 'flex', flexDirection: 'column', boxShadow: 'var(--shadow-md)' }}>
{/* Header */}
<div style={{ padding: '12px 16px', borderBottom: '1px solid var(--line-1)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexShrink: 0 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
{type === 'manual_input'
? <KeyRound size={14} style={{ color: 'var(--accent)' }}/>
: <Layers size={14} style={{ color: 'var(--accent)' }}/>}
<span style={{ fontSize: 13, fontWeight: 600, color: 'var(--fg-0)' }}>
{type === 'manual_input' ? 'Provide Missing IDs' : 'Choose an Option'}
</span>
</div>
<button onClick={onCancel} className="ico-btn"><X size={14}/></button>
</div>
<div style={{ padding: 20, overflowY: 'auto' }}>
{/* ── Manual input mode ── */}
{type === 'manual_input' && (
<>
<p style={{ fontSize: 12, color: 'var(--fg-2)', marginBottom: 16, lineHeight: 1.6 }}>
This step requires real IDs that could not be determined automatically.
Enter the correct values from your system or database.
</p>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 20 }}>
{missingKeys.map(key => (
<div key={key}>
<label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: 'var(--fg-2)', marginBottom: 5, textTransform: 'uppercase', letterSpacing: '0.06em' }}>
{key}
</label>
<input
type="text"
className="input"
placeholder={`Enter real value for ${key}`}
value={inputValues[key] || ''}
onChange={e => setInputValues(prev => ({ ...prev, [key]: e.target.value }))}
style={{ width: '100%', boxSizing: 'border-box' }}
/>
</div>
))}
</div>
<div style={{ display: 'flex', gap: 8 }}>
<button
className="btn-primary"
disabled={!allFilled}
onClick={() => onConfirm(inputValues)}
style={{ flex: 1, justifyContent: 'center', opacity: allFilled ? 1 : 0.45 }}
>
Save &amp; Execute
</button>
<button onClick={onCancel} className="btn" style={{ flex: 1, justifyContent: 'center' }}>
Cancel
</button>
</div>
</>
)}
{/* ── Selection mode (existing behaviour) ── */}
{type === 'selection' && (
<>
<p style={{ fontSize: 12, color: 'var(--fg-2)', marginBottom: 14, lineHeight: 1.6 }}>
Select one to save as <code style={{ color: 'var(--accent)' }}>{selectionPrompt.fieldName}</code>.
</p>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, marginBottom: 14 }}>
{(selectionPrompt.options || []).map((opt, idx) => (
<button
key={idx}
onClick={() => onSelect(opt)}
className="col-card"
style={{ textAlign: 'left', padding: '10px 14px', borderRadius: 6, cursor: 'pointer' }}
>
<div style={{ fontSize: 13, color: 'var(--fg-0)', fontWeight: 500, marginBottom: 2 }}>{opt.label || 'Option'}</div>
<div style={{ fontSize: 10.5, color: 'var(--fg-3)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{typeof opt.value === 'object' ? JSON.stringify(opt.value) : String(opt.value)}
</div>
</button>
))}
</div>
{selectionPrompt.responseBody && (
<details style={{ cursor: 'pointer' }}>
<summary style={{ fontSize: 11, color: 'var(--fg-3)', display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 }}>
<Code size={12}/> Raw response
</summary>
<pre className="code" style={{ maxHeight: 160 }}>
{(() => { try { return JSON.stringify(JSON.parse(selectionPrompt.responseBody), null, 2); } catch { return selectionPrompt.responseBody; } })()}
</pre>
</details>
)}
<button onClick={onCancel} className="btn" style={{ width: '100%', justifyContent: 'center', marginTop: 8 }}>
Cancel
</button>
</>
)}
</div>
</div>
</div>
);
}