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 @@ -9,6 +9,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
2 changes: 2 additions & 0 deletions @app/client/src/pages/admin/event/update/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type UpdateFormInitialValues = {
registrationStartTime: string
registrationEndTime: string
isHighlighted: boolean
highlightText: Record<string, string> | null
isDraft: boolean
headerImageFile: string
quotas: QuotasConnection
Expand All @@ -44,6 +45,7 @@ function constructInitialValues(values: any) {
"registrationStartTime",
"registrationEndTime",
"isHighlighted",
"highlightText",
"isDraft",
"headerImageFile",
"quotas",
Expand Down
2 changes: 2 additions & 0 deletions @app/client/src/translations/en/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"forms": {
"eventTime": "Event time",
"highlightEvent": "Highlighted event",
"highlightText": "Highlight text",
"highlightTextHelp": "Leave empty to show the default text \"Check this out!\".",
"isDraft": "Draft",
"isHighlighted": "Highlighted",
"isNotDraft": "Published",
Expand Down
2 changes: 2 additions & 0 deletions @app/client/src/translations/fi/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"forms": {
"eventTime": "Tapahtuman ajankohta",
"highlightEvent": "Korostettu tapahtuma",
"highlightText": "Korostuksen teksti",
"highlightTextHelp": "Jätä tyhjäksi, niin näytetään oletusteksti \"Nätti tapahtuma!\".",
"isDraft": "Luonnos",
"isHighlighted": "Korostettu",
"isNotDraft": "Julkaistu",
Expand Down
2 changes: 2 additions & 0 deletions @app/client/src/translations/se/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"forms": {
"eventTime": "Händelsetid",
"highlightEvent": "Markerad händelse",
"highlightText": "Markeringstext",
"highlightTextHelp": "Lämna tomt för att visa standardtexten \"Kolla in det här!\".",
"isDraft": "Utkast",
"isHighlighted": "Markerad",
"isNotDraft": "Publicerad",
Expand Down
3 changes: 2 additions & 1 deletion @app/components/src/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const EventCard: React.FC<EventCardProps> = ({ event }) => {
headerImageFile,
signupOpen,
isHighlighted,
highlightText,
} = event
const { t, lang } = useTranslation("home")

Expand Down Expand Up @@ -108,7 +109,7 @@ export const EventCard: React.FC<EventCardProps> = ({ event }) => {
<Ribbon
color={randomElementFromArray(rainbowColors)}
data-cy="eventcard-is-highlighted"
text={t("highlightText")}
text={highlightText?.[lang] || t("highlightText")}
>
{card}
</Ribbon>
Expand Down
24 changes: 24 additions & 0 deletions @app/components/src/EventForm/MainTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const MainTab: React.FC<MainTabProps> = (props) => {
supportedLanguages,
} = props
const { t, lang } = useTranslation("events")
const isHighlighted = Form.useWatch("isHighlighted")

function getUploadDefaultFileList(): Array<UploadFile> | undefined {
if (type === "update") {
Expand Down Expand Up @@ -265,6 +266,29 @@ export const MainTab: React.FC<MainTabProps> = (props) => {
>
<Switch data-cy="eventform-switch-highlight" />
</Form.Item>
{isHighlighted && (
<Form.Item
extra={t("forms.highlightTextHelp")}
label={t("forms.highlightText")}
>
<Group compact>
{selectedLanguages.map((l, i) => (
<Form.Item
key={l}
name={["highlightText", l.toLowerCase()]}
noStyle
>
<Input
data-cy={`eventform-input-highlight-text-${l}`}
maxLength={40}
placeholder={t(`common:lang.in.${l}`)}
style={i > 0 ? { marginTop: 5 } : undefined}
/>
</Form.Item>
))}
</Group>
</Form.Item>
)}
<Form.Item
getValueFromEvent={(e) => e[0]}
label={t("headerImage")}
Expand Down
20 changes: 19 additions & 1 deletion @app/components/src/EventForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type FormValues = {
eventTime?: dayjs.Dayjs[]
registrationTime?: dayjs.Dayjs[]
isHighlighted?: boolean
highlightText?: Scalars["TranslatedField"]["input"]
headerImageFile?: string
isDraft?: boolean
quotas?: Quota[]
Expand Down Expand Up @@ -140,6 +141,8 @@ export const EventForm: React.FC<EventFormProps> = (props) => {
quotas: formQuotas,
questions: formQuestions,
headerImageFile: headerFile,
isHighlighted,
highlightText: formHighlightText,
} = values

if (!formQuotas && (openQuotaSize < 1 || !openQuotaSize)) {
Expand All @@ -155,6 +158,20 @@ export const EventForm: React.FC<EventFormProps> = (props) => {
const slug = getEventSlug(name, eventTime)
const headerImageFile = headerFile?.originFileObj

// Keep only non-empty texts in the selected languages. An empty
// result is sent as null so the default ribbon text is shown.
const highlightTextEntries = Object.entries(
(isHighlighted && formHighlightText) || {}
)
.map(([l, text]) => [l, (text as string | undefined)?.trim()])
.filter(
([l, text]) => text && selectedLanguages.includes(l as string)
)
const highlightText =
highlightTextEntries.length > 0
? Object.fromEntries(highlightTextEntries)
: null

const event = {
...filterObjectByKeys(values, [
"ownerOrganizationId",
Expand All @@ -166,6 +183,7 @@ export const EventForm: React.FC<EventFormProps> = (props) => {
"isDraft",
]),
slug,
highlightText,
eventStartTime,
eventEndTime,
registrationStartTime,
Expand Down Expand Up @@ -219,7 +237,7 @@ export const EventForm: React.FC<EventFormProps> = (props) => {
}
setFormSubmitting(false)
},
[mutation, formRedirect, router, t, type, eventId]
[mutation, formRedirect, router, t, type, eventId, selectedLanguages]
)

const debounceTabErrors = useMemo(
Expand Down
128 changes: 128 additions & 0 deletions @app/db/migrations/current/3-event-highlight-text.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Highlighted events carry a ribbon on the event card. Its text used to be a
* fixed translation ("Nätti tapahtuma!"); `highlight_text` lets the event
* creator write their own, per language. A null value, or a missing language,
* falls back to the default translation in the client.
*/

alter table app_public.events add column if not exists highlight_text translated_field;

comment on column app_public.events.highlight_text is
E'Text shown on the ribbon of a highlighted event.';

grant
insert (highlight_text),
update (highlight_text)
on app_public.events to :DATABASE_VISITOR;

alter type app_public.event_input drop attribute if exists highlight_text;
alter type app_public.event_input add attribute highlight_text translated_field;

create or replace function app_public.create_event(
event app_public.event_input,
quotas app_public.create_event_quotas[],
questions app_public.create_event_questions[] default null
)
returns app_public.events as $$
#variable_conflict use_variable
declare
v_event app_public.events;
begin
-- Check permissions
call app_public.check_is_admin();

-- Create the event
insert into app_public.events(
slug,
name,
description,
location,
event_start_time,
event_end_time,
registration_start_time,
registration_end_time,
is_highlighted,
highlight_text,
is_draft,
header_image_file,
open_quota_size,
owner_organization_id,
category_id
)
values (
event.slug,
event.name,
event.description,
event.location,
event.event_start_time,
event.event_end_time,
event.registration_start_time,
event.registration_end_time,
event.is_highlighted,
event.highlight_text,
event.is_draft,
event.header_image_file,
event.open_quota_size,
event.owner_organization_id,
event.category_id
)
returning * into v_event;

-- Create quotas and questions
perform * from app_public.create_event_quotas(v_event.id, quotas);
perform * from app_public.create_event_questions(v_event.id, questions);

return v_event;
end;
$$ language plpgsql volatile security invoker set search_path = pg_catalog, public, pg_temp;

/*
* `highlight_text` is not coalesced like the other fields: a null must be able
* to clear a previously written text. It is instead updated together with
* `is_highlighted`, so partial updates that leave both out keep the old text.
*/
create or replace function app_public.update_event(
id uuid,
event app_public.event_input,
quotas app_public.update_event_quotas[],
questions app_public.update_event_questions[] default null
)
returns app_public.events as $$
#variable_conflict use_column
declare
v_event app_public.events;
begin
-- Check permissions
call app_public.check_is_admin();

-- Create the event
update app_public.events
set
slug = coalesce(event.slug, slug),
name = coalesce(event.name, name),
description = coalesce(event.description, description),
location = coalesce(event.location, location),
event_start_time = coalesce(event.event_start_time, event_start_time),
event_end_time = coalesce(event.event_end_time, event_end_time),
registration_start_time = coalesce(event.registration_start_time, registration_start_time),
registration_end_time = coalesce(event.registration_end_time, registration_end_time),
is_highlighted = coalesce(event.is_highlighted, is_highlighted),
highlight_text = case
when event.is_highlighted is null then highlight_text
else event.highlight_text
end,
is_draft = coalesce(event.is_draft, is_draft),
header_image_file = coalesce(event.header_image_file, header_image_file),
open_quota_size = coalesce(event.open_quota_size, open_quota_size),
owner_organization_id = coalesce(event.owner_organization_id, owner_organization_id),
category_id = coalesce(event.category_id, category_id)
where id = update_event.id
returning * into v_event;

-- Update quotas and questions
perform * from app_public.update_event_quotas(id, quotas);
perform * from app_public.update_event_questions(id, questions);

return v_event;
end;
$$ language plpgsql volatile security invoker set search_path = pg_catalog, public, pg_temp;
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ fragment EventFields on Event {
registrationStartTime
registrationEndTime
isHighlighted
highlightText
isDraft
headerImageFile
openQuotaSize
Expand Down
16 changes: 8 additions & 8 deletions @app/graphql/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"UpdateEventCategory": "940f0de83cc5a7fbcd2d8e2d1774a59556f759b117c0b6d8e5ce8c5584907eae",
"AdminListEvents": "ee0afc787cdba3845d8fe784c6585e07c101573c699914e3803ed9c17fb8360b",
"CreateEventPage": "77885919f782dbb117e2759c4918f2445a633ed0a98d08fd5d1ab699ebce9391",
"CreateEvent": "98965cb2bb84e54d0e0d6ba48046a829fc42776ce6b7b9eeae134dcae7036044",
"CreateEvent": "936b95b84ab4570162a3124685b9aa033c72a848ec5a288ff1cec143bf134a57",
"DeleteEvent": "75c86da8b31d18d79c4dcab26bacfffb860b4c7933568ca830731c793f815338",
"ListEventsPage": "f03f38c3d71fd696ef382a99987cf83cc85f699074616d593fbd4216e7de1a2f",
"TranslateText": "2fd1ef03df33a4dacf0b46162521f2bec22b99971807fb81a205aa5d36a0e59c",
"UpdateEventPage": "7e487496b03e301f627d86bce4edd2273740b18548ad91c12bd6575aaff34ad7",
"UpdateEvent": "063ffe79e5b7bcf7d58cc1b0742a2526dfd993ebd5550a37cc5d326b8fd35d00",
"UpdateEventPage": "8da3a080702c2a6460f1a925f38db2c29d2ead3bf046f243a90255a950b0dbd0",
"UpdateEvent": "3b54a951d1aa12e533adfdeea2ceca0ab7c74cc25b3560018bce199d4ee5b170",
"InviteToOrganization": "c639d16546c2d6c7133350ef65627885f7e11a1e33ec9ae099d0bb4a9b9af331",
"OrganizationBySlug": "7d4e6fe382bf3e0467c9372406e18fd1e63b6aa3f1aea2530a66c60cdfa3da2d",
"OrganizationPage": "e75fddfae08b7bdc7571c0cd3426cdda51dc0b336d6a428c214da7d7f2752708",
Expand All @@ -26,21 +26,21 @@
"AdminDeleteUser": "272d8236ba9669d320fc31b805cbeeb08662b4f7a510392a307694c420e030fd",
"AdminListUsers": "9dc8f24c328dc0dc2e150a71047eecfa5bbf8e350f9fa1b3e9bd3abef4a6edc0",
"SetAdminStatus": "9622d74eaeb7042221e04a2d63ed26a4e3c673071f7538537d36fdf1f453ba69",
"EventPage": "1583d624d064d3c3b0fc46fd55d971815a7a669d38c8f20fe06b2049fe048744",
"EventPage": "82bdfa19e629bf0bb458d0adad192caeda42ee89e4dc50837d76eedb65e24e19",
"EventRegistrations": "c22efb8e3e3226153a7be53c61321e72c94f3cbc667ca769cc056b4fee27678c",
"HomePageEvents": "368543083e66d7a6ae5e78654849ec0d94283752aece92394005e027bf3e429c",
"HomePage": "301da0928db49b18b443128fd731b8815df9fd05a090c4f6e648837bc2436754",
"HomePageEvents": "f2fefc947bd99546e9d9c7c8267b1563e4892fba88cfade450da6761d1f7dcd9",
"HomePage": "3bbf9bfad460e8a6f150520787a205e2d745383e21b8a749940f279807f2f7a5",
"CurrentTime": "f836d34508a8ee8ab07ca87bb086fe03dbddcf1fa40ffe912ef6143a843db460",
"Shared": "eb985e5bfabc266d0fc5637eda513cac8a293bc851b29e863dbf304c4932f7f1",
"AcceptOrganizationInvite": "29b135f119928bfc6de24b8aa6ec513ed62cb3cadf95eec1da607a3c760df7e9",
"CreateOrganization": "61c018fcf82eca2de4bf2fe5ca833cbf1586808421b10428aa99ba75b028cc6c",
"DeleteOrganization": "39f623b7dd9b3111922c0937f5985ef32d8de76b88898b043daaf53dc20877b2",
"InvitationDetail": "3d3ae0471e11f29477713606f9d884cb6d2a031b1a8bed9e220bec4c5e54337f",
"ClaimRegistrationToken": "c3c63bf12e25e4025a986f94781d706f7adb2261e91689d356069378faec2c4a",
"CreateEventRegistrationPage": "c80a1b7e4a79510cd8e544910e72dec734223574011e0a40bb00c78de8de310c",
"CreateEventRegistrationPage": "352b5b88c5fe83395845af0905c25533254a40eaafc9731e4a9cd2851b486e24",
"CreateEventRegistration": "e97c6726ce1d78c512935a15f46e8315e8ab2e50b2776d4fa1c92a5e8a54c566",
"DeleteEventRegistration": "be0f72e306dcf5e22dbaa962b5228422a5a0bd12dc68d688ee8b9a28b479318b",
"UpdateEventRegistrationPage": "2e4a7c74a71603bcec3debb7b11c003a481d28d6b25b130694e38f2760fcf7e9",
"UpdateEventRegistrationPage": "fe7ededd92bbd571b6394f7ecd32018c53c217595dc99173a5382795a86dc46a",
"UpdateEventRegistration": "a073a90b247942ecbca6dd214aa1b2dcbe42ab30618e881c8a8d90b1c5097739",
"AddEmail": "da27b66ae2e115cc90ba53748aaadae32ba97b016e2783550fe847089f7423c2",
"ChangePassword": "2532c897bead71cb8b9171c240298a47c4b6b13197886c990ccfcc937356ceab",
Expand Down
Loading
Loading