import {
Button,
Input,
Typography,
Dropdown,
Modal,
} from 'antd';
import React from 'react';
import {
withSiteId,
usabilityTesting,
usabilityTestingView,
usabilityTestingEdit,
} from 'App/routes';
import { useParams, useHistory } from 'react-router-dom';
import Breadcrumb from 'Shared/Breadcrumb';
import { EditOutlined, DeleteOutlined, MoreOutlined } from '@ant-design/icons';
import { useModal } from 'App/components/Modal';
import { observer } from 'mobx-react-lite';
import { useStore } from 'App/mstore';
import { confirm } from 'UI';
import StepsModal from './StepsModal';
import SidePanel from './SidePanel';
const menuItems = [
{
key: '1',
label: 'Change title/description',
icon: ,
},
{
key: '2',
label: 'Delete',
icon: ,
},
];
function TestEdit() {
const [newTestTitle, setNewTestTitle] = React.useState('');
const [newTestDescription, setNewTestDescription] = React.useState('');
const [isModalVisible, setIsModalVisible] = React.useState(false);
const { uxtestingStore } = useStore();
const [isConclusionEditing, setIsConclusionEditing] = React.useState(false);
const [isOverviewEditing, setIsOverviewEditing] = React.useState(false);
// @ts-ignore
const { siteId, testId } = useParams();
const { showModal, hideModal } = useModal();
const history = useHistory();
React.useEffect(() => {
if (testId && testId !== 'new') {
uxtestingStore.getTestData(testId);
}
}, []);
if (!uxtestingStore.instance) {
return
Loading...
;
}
const onSave = (isPreview?: boolean) => {
if (testId && testId !== 'new') {
uxtestingStore.updateTest(uxtestingStore.instance!).then((testId) => {
history.push(withSiteId(usabilityTestingView(testId!.toString()), siteId));
});
} else {
uxtestingStore.createNewTest(isPreview).then((test) => {
console.log(test);
if (isPreview) {
window.open(`${test.startingPath}?oruxt=${test.testId}`, '_blank', 'noopener,noreferrer');
history.push(withSiteId(usabilityTestingEdit(test.testId), siteId));
} else {
history.push(withSiteId(usabilityTestingView(test.testId), siteId));
}
});
}
};
const onClose = (confirmed: boolean) => {
if (confirmed) {
uxtestingStore.instance!.setProperty('title', newTestTitle);
uxtestingStore.instance!.setProperty('description', newTestDescription);
}
setNewTestDescription('');
setNewTestTitle('');
setIsModalVisible(false);
};
const onMenuClick = async ({ key }: { key: string }) => {
if (key === '1') {
setNewTestTitle(uxtestingStore.instance!.title);
setNewTestDescription(uxtestingStore.instance!.description);
setIsModalVisible(true);
}
if (key === '2') {
if (
await confirm({
confirmation:
'Are you sure you want to delete this usability test? This action cannot be undone.',
})
) {
uxtestingStore.deleteTest(testId).then(() => {
history.push(withSiteId(usabilityTesting(), siteId));
});
}
}
};
return (
<>
onClose(true)}
onCancel={() => onClose(false)}
footer={
onClose(true)}>
Save
}
>
Title
setNewTestTitle(e.target.value)}
/>
Test Objective (optional)
setNewTestDescription(e.target.value)}
placeholder="Share a brief statement about what you aim to discover through this study."
/>
{uxtestingStore.instance.title}
{uxtestingStore.instance.description}
}>
Starting point
{
uxtestingStore.instance!.setProperty('startingPath', e.target.value);
}}
/>
Test will begin on this page
Introduction & Guidelines
{isOverviewEditing ? (
uxtestingStore.instance!.setProperty('guidelines', e.target.value)}
/>
) : (
{uxtestingStore.instance?.guidelines?.length
? uxtestingStore.instance.guidelines
: 'Provide an overview of this user test to and input guidelines that can be of assistance to users at any point during the test.'}
)}
{isOverviewEditing ? (
<>
setIsOverviewEditing(false)}>
Save
{
uxtestingStore.instance!.setProperty('guidelines', '');
setIsOverviewEditing(false);
}}
>
Remove
>
) : (
setIsOverviewEditing(true)}>Add
)}
Task List
{uxtestingStore.instance!.tasks.map((task, index) => (
} />
{
uxtestingStore.instance!.setProperty(
'tasks',
uxtestingStore.instance!.tasks.filter(
(t) => t.title !== task.title && t.description !== task.description
)
);
}}
size={'small'}
icon={ }
/>
>
}
/>
))}
showModal(
{
uxtestingStore.instance!.setProperty('tasks', [
...uxtestingStore.instance!.tasks,
task,
]);
}}
/>,
{ right: true }
)
}
>
Add a task or question
Conclusion Message
{isConclusionEditing ? (
uxtestingStore.instance!.setProperty('conclusionMessage', e.target.value)
}
/>
) : (
{uxtestingStore.instance!.conclusionMessage}
)}
{isConclusionEditing ? (
<>
setIsConclusionEditing(false)}>
Save
{
uxtestingStore.instance!.setProperty('conclusionMessage', '');
setIsConclusionEditing(false);
}}
>
Remove
>
) : (
setIsConclusionEditing(true)}>Edit
)}
onSave(false)} onPreview={() => onSave(true)} />
>
);
}
export function Step({
buttons,
ind,
title,
description,
}: {
buttons?: React.ReactNode;
ind: number;
title: string;
description: string | null;
}) {
return (
);
}
export default observer(TestEdit);