Skip to content

Commit 9defb98

Browse files
authored
fix: only admin can see add registration checkbox LINK-2257 (#500)
* fix: only admin can see add registreation checkbox
1 parent bb29e65 commit 9defb98

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/domain/event/eventForm/EventForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ const EventForm: React.FC<EventFormProps> = ({
541541
<PriceSection
542542
event={event}
543543
isEditingAllowed={isEditingAllowed}
544+
isAdminUser={isAdminUser}
544545
/>
545546
</Section>
546547
<Section title={t(`event.form.sections.channels.${values.type}`)}>

src/domain/event/formSections/priceSection/PriceSection.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ import ValidationError from './validationError/ValidationError';
2828
interface Props {
2929
event?: EventFieldsFragment | null;
3030
isEditingAllowed: boolean;
31+
isAdminUser: boolean;
3132
}
3233

33-
const PriceSection: React.FC<Props> = ({ event, isEditingAllowed }) => {
34+
const PriceSection: React.FC<Props> = ({
35+
event,
36+
isEditingAllowed,
37+
isAdminUser,
38+
}) => {
3439
const { t } = useTranslation();
3540
const { user } = useUser();
3641

@@ -79,14 +84,15 @@ const PriceSection: React.FC<Props> = ({ event, isEditingAllowed }) => {
7984
name={EVENT_FIELDS.HAS_PRICE}
8085
/>
8186
</FormGroup>
82-
{featureFlagUtils.isFeatureEnabled('WEB_STORE_INTEGRATION') && (
83-
<Field
84-
component={CheckboxField}
85-
disabled={!isEditingAllowed || !hasPrice}
86-
label={t(`event.form.labelIsRegistrationPlanned.${type}`)}
87-
name={EVENT_FIELDS.IS_REGISTRATION_PLANNED}
88-
/>
89-
)}
87+
{featureFlagUtils.isFeatureEnabled('WEB_STORE_INTEGRATION') &&
88+
isAdminUser && (
89+
<Field
90+
component={CheckboxField}
91+
disabled={!isEditingAllowed || !hasPrice}
92+
label={t(`event.form.labelIsRegistrationPlanned.${type}`)}
93+
name={EVENT_FIELDS.IS_REGISTRATION_PLANNED}
94+
/>
95+
)}
9096

9197
<ValidationError />
9298
</FieldColumn>

src/domain/event/formSections/priceSection/__tests__/PriceSection.test.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ beforeEach(() => {
3737
mockAuthenticatedLoginState();
3838
});
3939

40+
const registrationCheckboxName =
41+
'Tapahtumalle luodaan Linked Events -ilmoittautuminen';
42+
4043
type InitialValues = {
4144
[EVENT_FIELDS.EVENT_INFO_LANGUAGES]: string[];
4245
[EVENT_FIELDS.HAS_PRICE]: boolean;
@@ -58,17 +61,19 @@ const defaultMocks = [mockedFreePriceGroupsResponse, mockedUserResponse];
5861
const renderPriceSection = ({
5962
initialValues,
6063
mocks = defaultMocks,
64+
isAdminUser = true,
6165
}: {
6266
initialValues?: Partial<InitialValues>;
6367
mocks?: MockedResponse[];
68+
isAdminUser?: boolean;
6469
} = {}) =>
6570
render(
6671
<Formik
6772
initialValues={{ ...defaultInitialValues, ...initialValues }}
6873
onSubmit={vi.fn()}
6974
validationSchema={publicEventSchema}
7075
>
71-
<PriceSection isEditingAllowed={true} />
76+
<PriceSection isEditingAllowed={true} isAdminUser={isAdminUser} />
7277
</Formik>,
7378
{ mocks }
7479
);
@@ -120,7 +125,7 @@ const getElement = (
120125
});
121126
case 'isRegistrationPlannedCheckbox':
122127
return screen.getByRole('checkbox', {
123-
name: 'Tapahtumalle luodaan Linked Events -ilmoittautuminen',
128+
name: registrationCheckboxName,
124129
});
125130
case 'priceGroupSelectButton':
126131
return screen.getByRole('button', { name: /Asiakasryhmä/ });
@@ -255,3 +260,18 @@ test('should add and remove price group', async () => {
255260
1
256261
);
257262
});
263+
264+
test('should not show registration checkbox to non admin user', async () => {
265+
const user = userEvent.setup();
266+
renderPriceSection({
267+
isAdminUser: false,
268+
});
269+
270+
await user.click(getElement('hasPriceCheckbox'));
271+
272+
expect(
273+
screen.queryByRole('checkbox', {
274+
name: registrationCheckboxName,
275+
})
276+
).not.toBeInTheDocument();
277+
});

0 commit comments

Comments
 (0)