-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forms): emfleshen language version tabs of survey editor
- Loading branch information
Showing
12 changed files
with
331 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
frontend/src/app/[locale]/events/[eventSlug]/surveys/[surveySlug]/edit/SurveyEditorView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Link from "next/link"; | ||
|
||
import { ReactNode } from "react"; | ||
import Card from "react-bootstrap/Card"; | ||
import CardBody from "react-bootstrap/CardBody"; | ||
import { Survey } from "./models"; | ||
import SurveyEditorTabs from "./SurveyEditorTabs"; | ||
import ViewContainer from "@/components/ViewContainer"; | ||
import ViewHeading from "@/components/ViewHeading"; | ||
import { getTranslations } from "@/translations"; | ||
|
||
interface Props { | ||
params: { | ||
locale: string; // UI language | ||
eventSlug: string; | ||
surveySlug: string; | ||
}; | ||
|
||
survey: Survey; | ||
activeTab: string; | ||
children: ReactNode; | ||
} | ||
|
||
export default function SurveyEditorView({ | ||
params, | ||
survey, | ||
activeTab, | ||
children, | ||
}: Props) { | ||
const { locale, eventSlug } = params; | ||
const translations = getTranslations(locale); | ||
const t = translations.Survey; | ||
|
||
return ( | ||
<ViewContainer> | ||
<Link className="link-subtle" href={`/events/${eventSlug}/surveys`}> | ||
< {t.actions.returnToSurveyList} | ||
</Link> | ||
|
||
<ViewHeading> | ||
{t.editSurveyPage.title} | ||
<ViewHeading.Sub>{survey.title}</ViewHeading.Sub> | ||
</ViewHeading> | ||
|
||
<SurveyEditorTabs | ||
eventSlug={eventSlug} | ||
survey={survey} | ||
translations={translations} | ||
active={activeTab} | ||
/> | ||
<Card className="mb-2"> | ||
<CardBody>{children}</CardBody> | ||
</Card> | ||
</ViewContainer> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
frontend/src/app/[locale]/events/[eventSlug]/surveys/[surveySlug]/edit/[language]/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use server"; | ||
|
||
export async function updateForm( | ||
eventSlug: string, | ||
surveySlug: string, | ||
language: string, | ||
formData: FormData, | ||
) { | ||
console.log("updateForm", { | ||
eventSlug, | ||
surveySlug, | ||
language, | ||
formData: Object.fromEntries(formData), | ||
}); | ||
} |
144 changes: 144 additions & 0 deletions
144
frontend/src/app/[locale]/events/[eventSlug]/surveys/[surveySlug]/edit/[language]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import Link from "next/link"; | ||
import { notFound } from "next/navigation"; | ||
|
||
import Card from "react-bootstrap/Card"; | ||
import CardBody from "react-bootstrap/CardBody"; | ||
import SurveyEditorTabs from "../SurveyEditorTabs"; | ||
import SurveyEditorView from "../SurveyEditorView"; | ||
import { updateForm } from "./actions"; | ||
import { graphql } from "@/__generated__"; | ||
import { getClient } from "@/apolloClient"; | ||
import { auth } from "@/auth"; | ||
import { getPropertiesFormFields } from "@/components/forms/getPropertiesFormFields"; | ||
import { Field } from "@/components/forms/models"; | ||
import { SchemaForm } from "@/components/forms/SchemaForm"; | ||
import SubmitButton from "@/components/forms/SubmitButton"; | ||
import SignInRequired from "@/components/SignInRequired"; | ||
import ViewContainer from "@/components/ViewContainer"; | ||
import ViewHeading from "@/components/ViewHeading"; | ||
import getPageTitle from "@/helpers/getPageTitle"; | ||
import { getTranslations } from "@/translations"; | ||
|
||
graphql(` | ||
fragment EditSurveyLanguagePage on SurveyType { | ||
slug | ||
title(lang: $locale) | ||
form(lang: $language) { | ||
title | ||
description | ||
thankYouMessage | ||
fields | ||
} | ||
languages { | ||
language | ||
} | ||
} | ||
`); | ||
|
||
const query = graphql(` | ||
query EditSurveyLanguagePageQuery( | ||
$eventSlug: String! | ||
$surveySlug: String! | ||
$language: String! | ||
$locale: String | ||
) { | ||
event(slug: $eventSlug) { | ||
name | ||
forms { | ||
survey(slug: $surveySlug) { | ||
...EditSurveyLanguagePage | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
interface Props { | ||
params: { | ||
locale: string; // UI language | ||
eventSlug: string; | ||
surveySlug: string; | ||
language: string; // language code of form being edited | ||
}; | ||
} | ||
|
||
export const revalidate = 0; | ||
|
||
export async function generateMetadata({ params }: Props) { | ||
const { locale, eventSlug, surveySlug, language } = params; | ||
const translations = getTranslations(locale); | ||
|
||
// TODO encap | ||
const session = await auth(); | ||
if (!session) { | ||
return translations.SignInRequired.metadata; | ||
} | ||
|
||
const t = translations.Survey; | ||
|
||
try { | ||
const { data } = await getClient().query({ | ||
query, | ||
variables: { locale, eventSlug, surveySlug, language }, | ||
}); | ||
|
||
if (!data.event?.forms?.survey?.form) { | ||
notFound(); | ||
} | ||
|
||
const title = getPageTitle({ | ||
translations, | ||
event: data.event, | ||
subject: data.event.forms.survey.form.title, | ||
viewTitle: t.editSurveyPage.title, | ||
}); | ||
|
||
return { title }; | ||
} catch (e) { | ||
console.log(JSON.stringify(e, null, 2)); | ||
} | ||
} | ||
|
||
export default async function EditSurveyPage({ params }: Props) { | ||
const { locale, eventSlug, surveySlug, language } = params; | ||
const translations = getTranslations(locale); | ||
const t = translations.Survey; | ||
const session = await auth(); | ||
|
||
// TODO encap | ||
if (!session) { | ||
return <SignInRequired messages={translations.SignInRequired} />; | ||
} | ||
|
||
const { data } = await getClient().query({ | ||
query, | ||
variables: { locale, eventSlug, surveySlug, language }, | ||
}); | ||
|
||
if (!data?.event?.forms?.survey?.form) { | ||
notFound(); | ||
} | ||
|
||
const survey = data.event.forms.survey; | ||
const form = data.event.forms.survey.form; | ||
|
||
const fields: Field[] = getPropertiesFormFields( | ||
translations.FormEditor.formPropertiesForm, | ||
); | ||
|
||
return ( | ||
<SurveyEditorView params={params} survey={survey} activeTab={language}> | ||
<form action={updateForm.bind(null, eventSlug, surveySlug, language)}> | ||
<SchemaForm | ||
fields={fields} | ||
values={form} | ||
messages={translations.SchemaForm} | ||
/> | ||
<SubmitButton>{t.actions.saveProperties}</SubmitButton> | ||
</form> | ||
</SurveyEditorView> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
frontend/src/app/[locale]/events/[eventSlug]/surveys/[surveySlug]/edit/models.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface Survey { | ||
slug: string; | ||
title?: string | null; | ||
languages: { | ||
language: string; | ||
}[]; | ||
} |
Oops, something went wrong.