Skip to content

Commit

Permalink
Fix/Change create/edit survey routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryczko committed Oct 14, 2024
1 parent ea2a39c commit 43b69cf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function SurveyResults() {
const router = useRouter();

const handleEditSurvey = () => {
router.push(`/survey/create/${surveyId}`);
router.push(`/survey/edit/${surveyId}`);
};

return (
Expand Down
34 changes: 34 additions & 0 deletions src/pages/survey/create/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Head from 'next/head';
import useTranslation from 'next-translate/useTranslation';

import SurveyCreator from 'features/surveys/features/SurveyCreator/SurveyCreator';
import { SurveyCreatorContext } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/context';
import { useCreateSurveyManager } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager';
import FullPageWrapper from 'layout/FullPageWrapper';
import withAnimation from 'shared/HOC/withAnimation';
import { usePreviewPanelManager } from 'features/surveys/features/SurveyCreator/managers/previewPanelManager/previewPanelManager';
import { PreviewPanelContext } from 'features/surveys/features/SurveyCreator/managers/previewPanelManager/context';

function SurveyCreatePage() {
const { t } = useTranslation('surveyCreate');

const manager = useCreateSurveyManager();
const previewPanelManager = usePreviewPanelManager();

return (
<FullPageWrapper>
<Head>
<title>{t('title')}</title>
<meta name="description" content={t('content')} />
</Head>

<SurveyCreatorContext.Provider value={manager}>
<PreviewPanelContext.Provider value={previewPanelManager}>
<SurveyCreator />
</PreviewPanelContext.Provider>
</SurveyCreatorContext.Provider>
</FullPageWrapper>
);
}

export default withAnimation(SurveyCreatePage);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { usePreviewPanelManager } from 'features/surveys/features/SurveyCreator/
import { PreviewPanelContext } from 'features/surveys/features/SurveyCreator/managers/previewPanelManager/context';

export async function getServerSideProps(context: NextPageContext) {
const surveyId = context.query.surveyId?.[0];
const surveyId = context.query.surveyId as string;
let surveyData;

if (surveyId) {
Expand All @@ -28,6 +28,7 @@ export async function getServerSideProps(context: NextPageContext) {

surveyData = await getSurveyData(surveyId, session.user?.id);


if (!surveyData) {
return {
redirect: {
Expand All @@ -44,7 +45,7 @@ export async function getServerSideProps(context: NextPageContext) {
};
}

function SurveyCreatePage({
function SurveyEditPage({
initialData,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
const { t } = useTranslation('surveyCreate');
Expand All @@ -68,4 +69,4 @@ function SurveyCreatePage({
);
}

export default withAnimation(SurveyCreatePage);
export default withAnimation(SurveyEditPage);

0 comments on commit 43b69cf

Please sign in to comment.