Skip to content

Commit

Permalink
Fix editing custom activities (#9916)
Browse files Browse the repository at this point in the history
* Rename const

* Move commonActivityCodes to utils

* Handle custom activities in humanizeActivityCode

* Fix dependency cycle for commonActivityCodes

* Localize names for humanizeActivityCode

* Move commonActivityCodes back to EditActivityModal

* Export new keys to JS

* Mark keys as used

* Use i18n on otherActivityCodes

(formerly commonActivityCodes)
  • Loading branch information
kr-matthews authored Sep 16, 2024
1 parent 846e0a3 commit 53afdfd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import {
Modal,
} from 'semantic-ui-react';
import { DateTime } from 'luxon';
import I18n from '../../../lib/i18n';
import useInputState from '../../../lib/hooks/useInputState';

const commonActivityCodes = {
'other-registration': 'On-site registration',
'other-checkin': 'Check-in',
'other-tutorial': 'Tutorial for new competitors',
'other-multi': 'Cube submission for 3x3x3 Multi-Blind',
'other-breakfast': 'Breakfast',
'other-lunch': 'Lunch',
'other-dinner': 'Dinner',
'other-awards': 'Awards',
'other-misc': 'Other',
};
const otherActivityCodes = [
'other-registration',
'other-checkin',
'other-tutorial',
'other-multi',
'other-breakfast',
'other-lunch',
'other-dinner',
'other-awards',
'other-misc',
];

const otherActivityCodeOptions = Object.entries(commonActivityCodes)
.map(([activityCode, description]) => ({
const otherActivityCodeOptions = otherActivityCodes
.map((activityCode) => ({
key: activityCode,
text: description,
text: I18n.t(`activity.${activityCode.substring(6)}`),
value: activityCode,
}));

Expand All @@ -44,7 +45,7 @@ function EditActivityModal({

// only if there is no name yet: assign a default name based on the activity code
if (!activityName && newActivityCode) {
setActivityName(commonActivityCodes[newActivityCode]);
setActivityName(I18n.t(`activity.${newActivityCode.substring(6)}`));
}

setActivityCode(evt, data);
Expand Down
10 changes: 7 additions & 3 deletions app/webpacker/lib/utils/wcif.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,23 @@ export const localizeActivityCode = (activityCode, wcifRound, wcifEvent) => {
};

export const humanizeActivityCode = (activityCode) => {
if (activityCode.startsWith('other-')) {
return I18n.t(`activity.${activityCode.substring(6)}`);
}

const { eventId, roundNumber, attempt } = parseActivityCode(activityCode);

const eventName = I18n.t(`events.${eventId}`);
const roundName = I18n.t('round.round_number', { round_number: roundNumber });

const tooltipText = `${eventName}, ${roundName}`;
const eventAndRoundName = `${eventName}, ${roundName}`;

if (attempt) {
const attemptName = I18n.t('attempts.attempt_name', { number: attempt });
return `${tooltipText}, ${attemptName}`;
return `${eventAndRoundName}, ${attemptName}`;
}

return tooltipText;
return eventAndRoundName;
};

export const shortLabelForActivityCode = (activityCode) => {
Expand Down
1 change: 1 addition & 0 deletions config/i18n-tasks.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ ignore_unused:
- 'contact.*.info'
- 'organizer_guidelines.*'
- 'merch.paragraphs.*'
- 'activity.*'
# Mark all events/continents/countries as used.
# FYI if a language doesn't translate one of them, it will appear in the missing keys, as long as it exists in English
- 'events.*'
Expand Down
1 change: 1 addition & 0 deletions config/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ translations:
patterns:
- "*.about.*"
- "*.activerecord.attributes.user.*"
- "*.activity.*"
- "*.common.*"
- "*.competitions.*"
- "*.countries.*"
Expand Down
11 changes: 11 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ en:
deadline:
description: "Qualification Deadline"
by_date: "by %{date}"
#context: other activities which occur in the schedule
activity:
registration: "On-site registration"
checkin: "Check-in"
tutorial: "Tutorial for new competitors"
multi: "Cube submission for 3x3x3 Multi-Blind"
breakfast: "Breakfast"
lunch: "Lunch"
dinner: "Dinner"
awards: "Awards"
misc: "Other"
#context: Common word used in multiple places on the website
common:
world: "World"
Expand Down

0 comments on commit 53afdfd

Please sign in to comment.