Skip to content

Commit

Permalink
Remove useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Nov 22, 2024
1 parent f4069bc commit fb1e719
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 129 deletions.
6 changes: 2 additions & 4 deletions src/pages/organizers/[organizerId]/ownerships/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ const Ownership = () => {
isApproveAction ? 'confirm' : 'reject'
}_modal`;

const organizerId = useMemo(
() => router.query.organizerId as string,
[router.query.organizerId],
);
const organizerId = router.query.organizerId as string;

const getOrganizerByIdQuery = useGetOrganizerByIdQuery({
id: organizerId,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { uniq } from 'lodash';
import { useRouter } from 'next/router';
import React, { useMemo, useRef, useState } from 'react';
import React, { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { UseQueryResult } from 'react-query';

Expand Down Expand Up @@ -38,10 +38,7 @@ export const OrganizerLabelsForm = ({ organizer }: OrganizerLabelProps) => {
});

const scope = ScopeTypes.ORGANIZERS;
const organizerId = useMemo(
() => router.query.organizerId as string,
[router.query.organizerId],
);
const organizerId = router.query.organizerId as string;

const options = labelsQuery.data?.member ?? [];
const [labels, setLabels] = useState<string[]>(
Expand Down
230 changes: 110 additions & 120 deletions src/pages/organizers/[organizerId]/preview/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getConfig from 'next/config';
import { useRouter } from 'next/router';
import { useMemo, useState } from 'react';
import { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { dehydrate, useQueryClient } from 'react-query';

Expand Down Expand Up @@ -40,11 +40,8 @@ const OrganizersPreview = () => {
const router = useRouter();
const { publicRuntimeConfig } = getConfig();
const isOwnershipEnabled = publicRuntimeConfig.ownershipEnabled === 'true';
const organizerId = router.query.organizerId as string;

const organizerId = useMemo(
() => router.query.organizerId as string,
[router.query.organizerId],
);
const getOrganizerByIdQuery = useGetOrganizerByIdQuery({
id: organizerId,
});
Expand Down Expand Up @@ -98,129 +95,122 @@ const OrganizersPreview = () => {
<Page.Title>{organizerName}</Page.Title>
<Page.Content>
<Stack>
{isOwnershipEnabled && (
<Stack flex={1}>
<Modal
title={t('organizers.ownerships.request.confirm_modal.title', {
organizerName: organizerName,
})}
confirmTitle={t(
'organizers.ownerships.request.confirm_modal.confirm',
)}
cancelTitle={t(
'organizers.ownerships.request.confirm_modal.cancel',
)}
visible={isQuestionModalVisible}
variant={ModalVariants.QUESTION}
onClose={() => setIsQuestionModalVisible(false)}
onConfirm={() => {
requestOwnershipMutation.mutate({
itemId: organizerId,
ownerId: userId,
});
}}
size={ModalSizes.MD}
>
<Box padding={4}>
<Trans
i18nKey="organizers.ownerships.request.confirm_modal.body"
values={{
organizerName: organizerName,
}}
/>
</Box>
</Modal>
{isOwnershipRequested && (
<Alert
variant={AlertVariants.PRIMARY}
marginBottom={4}
fullWidth
>
<Trans
i18nKey="organizers.ownerships.request.pending"
values={{
organizerName: organizerName,
}}
/>
</Alert>
<Stack flex={1}>
<Modal
title={t('organizers.ownerships.request.confirm_modal.title', {
organizerName: organizerName,
})}
confirmTitle={t(
'organizers.ownerships.request.confirm_modal.confirm',
)}
{isSuccessAlertVisible && (
<Alert
variant={AlertVariants.SUCCESS}
marginBottom={4}
closable
fullWidth
onClose={() => {
setIsSuccessAlertVisible(false);
}}
>
<Trans
i18nKey="organizers.ownerships.request.success"
values={{
organizerName: organizerName,
}}
/>
</Alert>
cancelTitle={t(
'organizers.ownerships.request.confirm_modal.cancel',
)}
{isErrorAlertVisible && (
<Alert
variant={AlertVariants.DANGER}
marginBottom={4}
fullWidth
closable
onClose={() => {
setIsErrorAlertVisible(false);
visible={isQuestionModalVisible}
variant={ModalVariants.QUESTION}
onClose={() => setIsQuestionModalVisible(false)}
onConfirm={() => {
requestOwnershipMutation.mutate({
itemId: organizerId,
ownerId: userId,
});
}}
size={ModalSizes.MD}
>
<Box padding={4}>
<Trans
i18nKey="organizers.ownerships.request.confirm_modal.body"
values={{
organizerName: organizerName,
}}
>
<Trans i18nKey="organizers.ownerships.request.confirm_modal.error" />
</Alert>
)}

<Inline spacing={5}>
<Stack flex={3}>
<OrganizerTable organizer={organizer} />
</Stack>
<Stack spacing={3.5} flex={1}>
{!canEdit && isOwnershipEnabled && !isOwnershipRequested && (
<Button
variant={ButtonVariants.PRIMARY}
onClick={() => setIsQuestionModalVisible(true)}
>
{t('organizers.detail.actions.request')}
</Button>
)}
{canEdit && (
<Link
variant={LinkButtonVariants.BUTTON_SECONDARY}
spacing={3}
iconName={Icons.PENCIL}
href={`/organizer/${organizerId}/edit`}
>
{t('organizers.detail.actions.edit')}
</Link>
)}
{canEdit && isOwnershipEnabled && !isOwnershipRequested && (
<Link
variant={LinkButtonVariants.BUTTON_SECONDARY}
spacing={3}
href={`/organizer/${organizerId}/ownerships`}
>
{t('organizers.detail.actions.manage')}
</Link>
)}
/>
</Box>
</Modal>
{isOwnershipRequested && (
<Alert variant={AlertVariants.PRIMARY} marginBottom={4} fullWidth>
<Trans
i18nKey="organizers.ownerships.request.pending"
values={{
organizerName: organizerName,
}}
/>
</Alert>
)}
{isSuccessAlertVisible && (
<Alert
variant={AlertVariants.SUCCESS}
marginBottom={4}
closable
fullWidth
onClose={() => {
setIsSuccessAlertVisible(false);
}}
>
<Trans
i18nKey="organizers.ownerships.request.success"
values={{
organizerName: organizerName,
}}
/>
</Alert>
)}
{isErrorAlertVisible && (
<Alert
variant={AlertVariants.DANGER}
marginBottom={4}
fullWidth
closable
onClose={() => {
setIsErrorAlertVisible(false);
}}
>
<Trans i18nKey="organizers.ownerships.request.confirm_modal.error" />
</Alert>
)}

<Inline spacing={5}>
<Stack flex={3}>
<OrganizerTable organizer={organizer} />
</Stack>
<Stack spacing={3.5} flex={1}>
{!canEdit && isOwnershipEnabled && !isOwnershipRequested && (
<Button
variant={ButtonVariants.PRIMARY}
onClick={() => setIsQuestionModalVisible(true)}
>
{t('organizers.detail.actions.request')}
</Button>
)}
{canEdit && (
<Link
variant={LinkButtonVariants.BUTTON_SECONDARY}
spacing={3}
iconName={Icons.ARROW_LEFT}
href={`/organizers`}
iconName={Icons.PENCIL}
href={`/organizer/${organizerId}/edit`}
>
{t('organizers.detail.actions.back')}
{t('organizers.detail.actions.edit')}
</Link>
</Stack>
</Inline>
</Stack>
)}
{!isOwnershipEnabled && <OrganizerTable organizer={organizer} />}
)}
{canEdit && isOwnershipEnabled && !isOwnershipRequested && (
<Link
variant={LinkButtonVariants.BUTTON_SECONDARY}
spacing={3}
href={`/organizer/${organizerId}/ownerships`}
>
{t('organizers.detail.actions.manage')}
</Link>
)}
<Link
variant={LinkButtonVariants.BUTTON_SECONDARY}
spacing={3}
iconName={Icons.ARROW_LEFT}
href={`/organizers`}
>
{t('organizers.detail.actions.back')}
</Link>
</Stack>
</Inline>
</Stack>
</Stack>
</Page.Content>
</Page>
Expand Down

0 comments on commit fb1e719

Please sign in to comment.