diff --git a/cypress/e2e/answerSurvey.cy.ts b/cypress/e2e/answerSurvey.cy.ts index 04d29d18..b51a3a4f 100644 --- a/cypress/e2e/answerSurvey.cy.ts +++ b/cypress/e2e/answerSurvey.cy.ts @@ -11,8 +11,9 @@ describe('Answering survey tests', () => { cy.get('[data-test-id="create-survey"]').click(); cy.url().should('include', '/survey/create'); + cy.get('[data-test-id="expand-templates"]').click(); cy.get('[data-test-id="start-from-scratch-field"]').click(); - cy.get('[data-test-id="start-from-scratch-button"]').click(); + cy.get('[data-test-id="confirm-template-change"]').click(); cy.get('[data-test-id="add-question-button"]').click(); cy.get('[data-test-id="emoji-question-button"]').click(); cy.get('[data-test-id="add-question-button"]').click(); diff --git a/cypress/e2e/createSurvey.cy.ts b/cypress/e2e/createSurvey.cy.ts index 8e9789e3..88ac9dd6 100644 --- a/cypress/e2e/createSurvey.cy.ts +++ b/cypress/e2e/createSurvey.cy.ts @@ -9,8 +9,10 @@ describe('Creating survey tests', () => { cy.get('[data-test-id="create-survey"]').click(); cy.url().should('include', '/survey/create'); + cy.get('[data-test-id="expand-templates"]').click(); cy.get('[data-test-id="start-from-scratch-field"]').click(); - cy.get('[data-test-id="start-from-scratch-button"]').click(); + cy.get('[data-test-id="confirm-template-change"]').click(); + cy.get('[data-test-id="add-question-button"]').click(); cy.get('[data-test-id="emoji-question-button"]').click(); cy.get('[data-test-id="add-question-button"]').click(); diff --git a/src/features/surveys/features/SurveyCreator/SurveyCreator.tsx b/src/features/surveys/features/SurveyCreator/SurveyCreator.tsx index 39b26b95..48b07ef3 100644 --- a/src/features/surveys/features/SurveyCreator/SurveyCreator.tsx +++ b/src/features/surveys/features/SurveyCreator/SurveyCreator.tsx @@ -2,37 +2,23 @@ import React from 'react'; import clsx from 'clsx'; import { usePreviewPanelContext } from 'features/surveys/features/SurveyCreator/managers/previewPanelManager/context'; import PreviewPanel from 'features/surveys/features/SurveyCreator/components/PreviewPanel/PreviewPanel'; -import { useSurveyCreatorContext } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/context'; -import dynamic from 'next/dynamic'; import CreatorContent from 'features/surveys/features/SurveyCreator/components/CreatorContent/CreatorContent'; -const Templates = dynamic( - () => - import( - 'features/surveys/features/SurveyCreator/components/Templates/Templates' - ), - { ssr: false } -); - export default function SurveyCreator() { - const { isPanelOpened } = usePreviewPanelContext(); - const { isEditMode, isTemplatePicked } = useSurveyCreatorContext(); + const { isPanelOpened, openedWithoutAnimation } = usePreviewPanelContext(); return ( <>
- {!isTemplatePicked && !isEditMode ? ( - - ) : ( - - )} +
diff --git a/src/features/surveys/features/SurveyCreator/components/CreatorContent/CreatorContent.tsx b/src/features/surveys/features/SurveyCreator/components/CreatorContent/CreatorContent.tsx index e5988855..4c6876ee 100644 --- a/src/features/surveys/features/SurveyCreator/components/CreatorContent/CreatorContent.tsx +++ b/src/features/surveys/features/SurveyCreator/components/CreatorContent/CreatorContent.tsx @@ -3,10 +3,15 @@ import ActionButtons from 'features/surveys/features/SurveyCreator/components/Ac import QuestionsSection from 'features/surveys/features/SurveyCreator/components/QuestionsSection/QuestionsSection'; import TitleAndConfigSection from 'features/surveys/features/SurveyCreator/components/TitleAndConfigSection/TitleAndConfigSection'; import withAnimation from 'shared/HOC/withAnimation'; +import Templates from 'features/surveys/features/SurveyCreator/components/Templates/Templates'; +import { useSurveyCreatorContext } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/context'; function CreatorContent() { + const { isEditMode } = useSurveyCreatorContext(); + return ( <> + {!isEditMode && } diff --git a/src/features/surveys/features/SurveyCreator/components/PreviewPanel/PreviewPanel.tsx b/src/features/surveys/features/SurveyCreator/components/PreviewPanel/PreviewPanel.tsx index 84fa545f..5e1010b8 100644 --- a/src/features/surveys/features/SurveyCreator/components/PreviewPanel/PreviewPanel.tsx +++ b/src/features/surveys/features/SurveyCreator/components/PreviewPanel/PreviewPanel.tsx @@ -9,8 +9,13 @@ import Button from 'shared/components/Button/Button'; export default function PreviewPanel() { const { questions, title, surveyOptions } = useSurveyCreatorContext(); - const { isPanelOpened, togglePanel, handleRestart, restartTrigger } = - usePreviewPanelContext(); + const { + isPanelOpened, + togglePanel, + handleRestart, + restartTrigger, + openedWithoutAnimation, + } = usePreviewPanelContext(); return ( <> @@ -23,7 +28,9 @@ export default function PreviewPanel() {
diff --git a/src/features/surveys/features/SurveyCreator/components/Templates/TemplateItem.tsx b/src/features/surveys/features/SurveyCreator/components/Templates/TemplateItem.tsx index ede0edb4..d45cebc2 100644 --- a/src/features/surveys/features/SurveyCreator/components/Templates/TemplateItem.tsx +++ b/src/features/surveys/features/SurveyCreator/components/Templates/TemplateItem.tsx @@ -1,50 +1,28 @@ import React from 'react'; -import { Template } from 'features/surveys/features/SurveyCreator/components/Templates/Templates'; import clsx from 'clsx'; -import Button, { ButtonVariant } from 'shared/components/Button/Button'; interface TemplateItemProps { - template?: Template; title?: string; onTemplatePreview?: (event: React.MouseEvent) => void; - onTemplatePick: (event: React.MouseEvent) => void; - isInPreview: boolean; - buttonContent?: string; fieldTestSelector?: string; - buttonTestSelector?: string; } export default function TemplateItem({ - template, title, onTemplatePreview, - onTemplatePick, - isInPreview, - buttonContent, fieldTestSelector, - buttonTestSelector, }: TemplateItemProps) { return (
onTemplatePreview?.(e)} data-test-id={fieldTestSelector} className={clsx( - 'flex h-[140px] flex-grow cursor-pointer flex-col items-center rounded border border-zinc-600/50 px-4 pb-4 shadow', - template ? 'border-solid bg-zinc-50' : 'bg-white', - isInPreview ? 'pt-2' : 'pt-4' + 'flex h-[60px] flex-grow cursor-pointer flex-col items-center rounded border border-zinc-300 bg-white px-4 hover:bg-zinc-50' )} > -
{title || 'Blank'}
- {isInPreview && ( - - )} +
+ {title || 'Blank form'} +
); } diff --git a/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx b/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx index 2511c476..5c42d067 100644 --- a/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx +++ b/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx @@ -4,8 +4,10 @@ import { useSurveyCreatorContext } from 'features/surveys/features/SurveyCreator import TemplateItem from 'features/surveys/features/SurveyCreator/components/Templates/TemplateItem'; import { TEMPLATES } from 'features/surveys/features/SurveyCreator/constants/Templates'; import { DraftQuestion } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager'; -import clsx from 'clsx'; import withAnimation from 'shared/HOC/withAnimation'; +import StyledDialog from 'shared/components/StyledDialog/StyledDialog'; +import Button, { ButtonVariant } from 'shared/components/Button/Button'; +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/outline'; export interface Template { title: string; @@ -13,113 +15,100 @@ export interface Template { } function Templates() { - const { togglePanel, isPanelOpened, handleRestart } = - usePreviewPanelContext(); + const { handleRestart } = usePreviewPanelContext(); - const { - selectTemplate, - getDraftSurveyFromSessionStorage, - setIsTemplatePicked, - } = useSurveyCreatorContext(); + const { selectTemplate } = useSurveyCreatorContext(); - const [previewIndex, setPreviewIndex] = useState( - getDraftSurveyFromSessionStorage() ? 0 : 1 - ); - - const toggleOnLargeScreen = () => { - if (window.innerWidth > 1280 && !isPanelOpened) { - togglePanel(); - } - }; - - const handleContinueLastSurveyPreview = ( - event: React.MouseEvent - ) => { - event.stopPropagation(); - const draftSurvey = getDraftSurveyFromSessionStorage(); - selectTemplate(draftSurvey?.title ?? '', draftSurvey?.questions ?? []); - handleRestart(); - setPreviewIndex(0); - toggleOnLargeScreen(); - }; + const [showGallery, setShowGallery] = useState(false); + const [isWarningOpen, setIsWarningOpen] = useState(false); + const [pendingTemplate, setPendingTemplate] = useState