Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fragment EventPage_Question on EventQuestion {
label
isRequired
data
prefill
}

fragment EventPage_Event on Event {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
fragment CreateEventRegistrationPage_Query on Query {
...SharedLayout_Query
currentUser {
id
registrationProfile {
...RegistrationProfile
}
}
eventBySlug(slug: $slug) {
...EventPage_Event
}
Expand Down
27 changes: 27 additions & 0 deletions @app/client/src/graphql/user/RegistrationProfile.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fragment RegistrationProfile on RegistrationProfile {
userId
telegram
dietaryRestrictions
}

query RegistrationProfile {
currentUser {
id
registrationProfile {
...RegistrationProfile
}
}
}

mutation SetRegistrationProfile(
$telegram: String!
$dietaryRestrictions: String!
) {
setRegistrationProfile(
input: { telegram: $telegram, dietaryRestrictions: $dietaryRestrictions }
) {
registrationProfile {
...RegistrationProfile
}
}
}
1 change: 1 addition & 0 deletions @app/client/src/pages/admin/event/update/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function constructInitialValues(values: any) {
"label",
"isRequired",
"data",
"prefill",
])
)
const languages = Object.keys(name || {})
Expand Down
16 changes: 15 additions & 1 deletion @app/client/src/pages/event/[slug]/register/[quotaId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useTranslation,
} from "@app/components"
import {
QuestionPrefill,
useCreateEventRegistrationPageQuery,
useDeleteEventRegistrationMutation,
} from "@app/graphql"
Expand All @@ -35,15 +36,28 @@ const EventRegistrationPage: NextPage = () => {
const quota = data?.quota
const { signupClosed, signupUpcoming } = event || {}

const { name, primaryEmail } = currentUser || {}
const { name, primaryEmail, registrationProfile } = currentUser || {}
// TODO: The users table schema could be changed to include first
// and last names. For now infer first and last name like this...
const [firstName, lastName] = name ? name.split(" ") : []

// Answers to questions marked for prefill come from the registration profile
const prefillValues = {
[QuestionPrefill.Telegram]: registrationProfile?.telegram,
[QuestionPrefill.DietaryRestrictions]:
registrationProfile?.dietaryRestrictions,
}
const answers = Object.fromEntries(
(event?.eventQuestions?.nodes || [])
.filter((q) => q.prefill && prefillValues[q.prefill])
.map((q) => [q.id, prefillValues[q.prefill]])
)

const formInitialValues = {
firstName,
lastName,
email: primaryEmail,
answers,
}

const [, deleteRegistration] = useDeleteEventRegistrationMutation()
Expand Down
95 changes: 93 additions & 2 deletions @app/client/src/pages/settings/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
} from "@app/components"
import {
SharedLayout_UserFragment,
useRegistrationProfileQuery,
useSetRegistrationProfileMutation,
useSharedQuery,
useUpdateUserMutation,
} from "@app/graphql"
import { formItemLayout, getCodeFromError, tailFormItemLayout } from "@app/lib"
import { Alert, Button, Form, Input } from "antd"
import { Alert, Button, Form, Input, Typography } from "antd"

import type { NextPage } from "next"

Expand All @@ -24,7 +26,10 @@ const Settings_Profile: NextPage = () => {
return (
<SettingsLayout href="/settings/profile" query={query}>
{data?.currentUser ? (
<ProfileSettingsForm user={data.currentUser} />
<>
<ProfileSettingsForm user={data.currentUser} />
<RegistrationProfileForm />
</>
) : fetching ? (
t("common:loading")
) : error ? (
Expand Down Expand Up @@ -131,3 +136,89 @@ function ProfileSettingsForm({ user }: ProfileSettingsFormProps) {
</div>
)
}

function RegistrationProfileForm() {
const { t } = useTranslation("settings")
const [query] = useRegistrationProfileQuery()
const [{ error }, setRegistrationProfile] =
useSetRegistrationProfileMutation()
const [success, setSuccess] = useState(false)

const handleSubmit = useCallback(
async (values) => {
setSuccess(false)
const { error } = await setRegistrationProfile({
telegram: values.telegram ?? "",
dietaryRestrictions: values.dietaryRestrictions ?? "",
})
if (!error) setSuccess(true)
},
[setRegistrationProfile]
)

if (query.fetching && !query.data) return <>{t("common:loading")}</>
if (query.error) return <ErrorAlert error={query.error} />

const { telegram, dietaryRestrictions } =
query.data?.currentUser?.registrationProfile || {}

return (
<div>
<PageHeader title={t("titles.registrationProfile")} />
<Typography.Paragraph type="secondary">
{t("registrationProfile.description")}
</Typography.Paragraph>
<Form
{...formItemLayout}
initialValues={{ telegram, dietaryRestrictions }}
onFinish={handleSubmit}
>
<Form.Item
label={t("form.label.telegram")}
name="telegram"
rules={[{ max: 64, message: t("form.messages.telegramTooLong") }]}
>
<Input data-cy="settings-input-telegram" />
</Form.Item>
<Form.Item
label={t("form.label.dietaryRestrictions")}
name="dietaryRestrictions"
rules={[
{
max: 1000,
message: t("form.messages.dietaryRestrictionsTooLong"),
},
]}
>
<Input.TextArea
autoSize={{ minRows: 2 }}
data-cy="settings-input-dietary-restrictions"
/>
</Form.Item>
{error ? (
<Form.Item {...tailFormItemLayout}>
<ErrorAlert
error={error}
message={t("errors.errorUpdatingRegistrationProfile")}
/>
</Form.Item>
) : success ? (
<Form.Item {...tailFormItemLayout}>
<Alert
message={t("form.feedback.registrationProfileUpdated")}
type="success"
/>
</Form.Item>
) : null}
<Form.Item {...tailFormItemLayout}>
<Button
data-cy="settings-button-update-registration-profile"
htmlType="submit"
>
{t("buttons.updateRegistrationProfile")}
</Button>
</Form.Item>
</Form>
</div>
)
}
4 changes: 4 additions & 0 deletions @app/client/src/translations/en/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"numRegistrations": "Registered people",
"openQuota": "Open quota",
"organizer": "Organizer",
"prefill": {
"DIETARY_RESTRICTIONS": "Dietary restrictions",
"TELEGRAM": "Telegram"
},
"queued": "Queue",
"quota": "Quota",
"removeOption": "Remove option",
Expand Down
15 changes: 13 additions & 2 deletions @app/client/src/translations/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"resetPassphrase": "Reset passphrase",
"returnHome": "Return to homepage",
"updateProfile": "Update profile",
"updateRegistrationProfile": "Update registration details",
"wantToDeleteAccount": "I want to delete my account"
},
"errors": {
"accountDeleteFailedOrgOwner1": "You cannot delete your account whilst you are the owner of an organization.",
"accountDeleteFailedOrgOwner2": "For each organization you are the owner of, please either assign your ownership to another user or delete the organization to continue.",
"deleteFailed": "Requesting deletion failed",
"errorUpdatingRegistrationProfile": "Updating registration details failed",
"errorUpdatingUsername": "Error updating username",
"incorrectOldPassword": "Incorrect old passphrase",
"usernameTaken": "This username is already in use, please pick a different name"
Expand All @@ -22,18 +24,23 @@
"emailAddFailed": "Error adding email",
"passwordChangeFailed": "Changing passphrase failed",
"passwordChanged": "Password changed!",
"profileUpdated": "Profile updated"
"profileUpdated": "Profile updated",
"registrationProfileUpdated": "Registration details updated"
},
"label": {
"dietaryRestrictions": "Dietary restrictions",
"newEmail": "New email",
"newPassphrase": "New passphrase",
"oldPassphrase": "Old passphrase"
"oldPassphrase": "Old passphrase",
"telegram": "Telegram"
},
"messages": {
"dietaryRestrictionsTooLong": "Dietary restrictions can be at most 1000 characters",
"email": "Please enter an email address",
"name": "Please enter your name",
"newPassword": "Please confirm your passphrase",
"oldPassword": "Please input your passphrase",
"telegramTooLong": "Telegram can be at most 64 characters",
"username": "Please choose a username"
}
},
Expand Down Expand Up @@ -84,11 +91,15 @@
"socialLoginNoPassword": "You registered your account through social login, so you do not currently have a passphrase. If you would like a passphrase, press the button below to request a passphrase reset email to '{{email}}' (you can choose a different email by making it primary in)"
}
},
"registrationProfile": {
"description": "These details prefill the Telegram and dietary restriction questions in registration forms. Only you can see them, and they are updated when you register to an event."
},
"titles": {
"accounts": "Linked accounts",
"delete": "Delete account",
"emails": "Email addresses",
"index": "Edit profile",
"registrationProfile": "Registration details",
"security": "Change passphrase"
}
}
4 changes: 4 additions & 0 deletions @app/client/src/translations/fi/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"numRegistrations": "Ilmoittautuneita",
"openQuota": "Avoin kiintiö",
"organizer": "Järjestäjä",
"prefill": {
"DIETARY_RESTRICTIONS": "Erityisruokavaliot",
"TELEGRAM": "Telegram"
},
"queued": "Jonossa",
"quota": "Kiintiö",
"removeOption": "Poista vaihtoehto",
Expand Down
15 changes: 13 additions & 2 deletions @app/client/src/translations/fi/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"resetPassphrase": "Resetoi salasana",
"returnHome": "Palaa etusivulle",
"updateProfile": "Päivitä tiedot",
"updateRegistrationProfile": "Päivitä ilmoittautumistiedot",
"wantToDeleteAccount": "Haluan poistaa käyttäjäni"
},
"errors": {
"accountDeleteFailedOrgOwner1": "Et voi poistaa tiliäsi, kun olet organisaation omistaja.",
"accountDeleteFailedOrgOwner2": "Määritä omistajuutesi toiselle käyttäjälle tai poista organisaatio jokaisen omistamasi organisaation kohdalla.",
"deleteFailed": "Poistopyyntö epäonnistui",
"errorUpdatingRegistrationProfile": "Ilmoittautumistietojen päivittäminen epäonnistui",
"errorUpdatingUsername": "Virhe päivitettäesssä käyttäjänimeä",
"incorrectOldPassword": "Väärä vanha salasana",
"usernameTaken": "Tämä käyttäjänimi on jo käytössä, valitse toinen käyttäjänimi"
Expand All @@ -22,18 +24,23 @@
"emailAddFailed": "Virhe lisättäessä sähköpostia",
"passwordChangeFailed": "Salasanan vaihtaminen epäonnistui",
"passwordChanged": "Salasana vaihdettu!",
"profileUpdated": "Profiili päivitetty"
"profileUpdated": "Profiili päivitetty",
"registrationProfileUpdated": "Ilmoittautumistiedot päivitetty"
},
"label": {
"dietaryRestrictions": "Erityisruokavaliot",
"newEmail": "Uusi sähköpostil",
"newPassphrase": "Uusi salasana",
"oldPassphrase": "Vanha salasana"
"oldPassphrase": "Vanha salasana",
"telegram": "Telegram"
},
"messages": {
"dietaryRestrictionsTooLong": "Erityisruokavaliot saavat olla enintään 1000 merkkiä",
"email": "Kirjoita sähköpostiosoite",
"name": "Kirjoita nimesi",
"newPassword": "Vahvista tunnuslause",
"oldPassword": "Kirjoita salasana",
"telegramTooLong": "Telegram saa olla enintään 64 merkkiä",
"username": "Valitse käyttäjätunnus"
}
},
Expand Down Expand Up @@ -84,11 +91,15 @@
"socialLoginNoPassword": "Rekisteröit tilisi sosiaalisen kirjautumisen kautta, joten sinulla ei ole tällä hetkellä salasanaa. Jos haluat tunnuslauseen, paina alla olevaa painiketta ja pyydä salasanan vaihtosähköposti osoitteeseen {{email}} (voit valita toisen sähköpostin asettamalla sen ensisijaiseksi"
}
},
"registrationProfile": {
"description": "Näillä tiedoilla esitäytetään ilmoittautumislomakkeen telegram- ja erityisruokavaliokysymykset. Tiedot näkyvät vain sinulle, ja ne päivittyvät, kun ilmoittaudut tapahtumaan."
},
"titles": {
"accounts": "Linkitetyt tilit",
"delete": "Poista käyttäjä",
"emails": "Sähköpostiosoitteet",
"index": "Muokkaa tiliä",
"registrationProfile": "Ilmoittautumistiedot",
"security": "Vaihda salasana"
}
}
4 changes: 4 additions & 0 deletions @app/client/src/translations/se/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"numRegistrations": "Registrerade personer",
"openQuota": "Öppen kvot",
"organizer": "Arrangör",
"prefill": {
"DIETARY_RESTRICTIONS": "Specialdieter",
"TELEGRAM": "Telegram"
},
"queued": "Kö",
"quota": "Kvota",
"removeOption": "Ta bort alternativ",
Expand Down
Loading
Loading