Skip to content

Commit

Permalink
fixed save bug
Browse files Browse the repository at this point in the history
  • Loading branch information
acao22 committed Nov 6, 2024
1 parent 91d2e2d commit 029510a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 45 additions & 37 deletions src/app/editor/components/ReferenceData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,43 +151,51 @@ const ReferenceData = ({ treatment, stageIndex }: ReferenceDataProps) => {
Stage Refs and Dependencies
</h2>

{references.map((reference, index) => {
const savedValue = jsonData[`stage_${stageIndex}`]?.[reference] || ''
const inputValue = inputValues[`stage_${stageIndex}`]?.[reference] || ''

return (
<div key={index} className="mb-6">
<label className="block text-sm font-medium text-gray-700">
{formatReference(reference)}
</label>

{/* saved val */}
{savedValue && (
<p className="text-sm text-gray-500 mt-1">
<strong>Saved Value:</strong> {savedValue}
</p>
)}

{/* input val */}
<input
type="text"
className="mt-2 block w-full rounded-md border-gray-300 bg-gray-100 p-2 shadow-sm focus:ring-indigo-500 focus:border-indigo-500"
placeholder={`Enter value for ${getPlaceholderText(
formatReference(reference)
)}`}
value={inputValue}
onChange={(e) => handleInputChange(reference, e.target.value)}
/>
</div>
)
})}

<button
onClick={saveAsJson}
className="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Save
</button>
{references.length > 0 ? (
<>
{references.map((reference, index) => {
const savedValue =
jsonData[`stage_${stageIndex}`]?.[reference] || ''
const inputValue =
inputValues[`stage_${stageIndex}`]?.[reference] || ''

return (
<div key={index} className="mb-6">
<label className="block text-sm font-medium text-gray-700">
{formatReference(reference)}
</label>

{/* saved val */}
{savedValue && (
<p className="text-sm text-gray-500 mt-1">
<strong>Saved Value:</strong> {savedValue}
</p>
)}

{/* input val */}
<input
type="text"
className="mt-2 block w-full rounded-md border-gray-300 bg-gray-100 p-2 shadow-sm focus:ring-indigo-500 focus:border-indigo-500"
placeholder={`Enter value for ${getPlaceholderText(
formatReference(reference)
)}`}
value={inputValue}
onChange={(e) => handleInputChange(reference, e.target.value)}
/>
</div>
)
})}

<button
onClick={saveAsJson}
className="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Save
</button>
</>
) : (
<p className="text-sm text-gray-500">No references found</p>
)}
</div>
)
}
Expand Down

0 comments on commit 029510a

Please sign in to comment.