2025-07-10 16:34:53 -07:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2025-07-24 12:11:32 -07:00
|
|
|
|
|
|
|
interface Step {
|
|
|
|
step_number: number;
|
|
|
|
instruction: string;
|
|
|
|
}
|
2025-07-10 16:34:53 -07:00
|
|
|
|
|
|
|
interface AddBulkStepsProps {
|
|
|
|
steps: Step[];
|
|
|
|
onChange?: (steps: Step[]) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AddBulkSteps: React.FC<AddBulkStepsProps> = ({ steps, onChange }) => {
|
|
|
|
const [textValue, setTextValue] = useState<string>('');
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const textRepresentation = steps.map(step =>
|
2025-07-24 12:11:32 -07:00
|
|
|
`${step.instruction}`
|
2025-07-10 16:34:53 -07:00
|
|
|
).join('\n');
|
|
|
|
setTextValue(textRepresentation);
|
|
|
|
}, [steps]);
|
|
|
|
|
|
|
|
const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
|
|
setTextValue(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const parseAndUpdate = (value: string) => {
|
|
|
|
const lines = value.split('\n').filter(line => line.trim() !== '');
|
|
|
|
|
2025-07-24 12:11:32 -07:00
|
|
|
const parsedSteps: Step[] = lines.map((line, idx) => {
|
|
|
|
return { step_number: idx + 1, instruction: line }
|
2025-07-10 16:34:53 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
if (onChange) onChange(parsedSteps);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
parseAndUpdate(textValue);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleBlur = () => {
|
|
|
|
parseAndUpdate(textValue);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2025-08-20 10:06:23 -07:00
|
|
|
<h3 className="text-xl font-bold text-[var(--color-secondaryTextDark)]">Steps:</h3>
|
2025-07-10 16:34:53 -07:00
|
|
|
<textarea
|
2025-07-11 17:06:41 -07:00
|
|
|
rows={8}
|
2025-07-10 16:34:53 -07:00
|
|
|
value={textValue}
|
|
|
|
onChange={handleInputChange}
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
onBlur={handleBlur}
|
2025-08-05 15:09:52 -07:00
|
|
|
placeholder="Enter steps separated by new line"
|
2025-08-20 10:06:23 -07:00
|
|
|
className="mb-4 p-2 border border-[var(--color-primaryBorder)] rounded w-full"
|
2025-07-10 16:34:53 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AddBulkSteps;
|