Skip to content

Commit

Permalink
removed unnecessary if/else comparisions
Browse files Browse the repository at this point in the history
  • Loading branch information
aatbip committed Feb 8, 2024
1 parent ea24ab7 commit d0ed649
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/app/manage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ManagePageContainer } from './views/ManagePageContainer';
import { SimpleButton } from '@/components/styled/SimpleButton';
import { apiUrl } from '@/config';
import { CustomFieldAccessResponse } from '@/types/customFieldAccess';
import { Settings } from '@mui/icons-material';
import { ProfileLinks } from '@/types/settings';

export const revalidate = 0;

Expand Down Expand Up @@ -75,14 +77,16 @@ export default async function ManagePage({ searchParams }: { searchParams: { tok
/>

<Stack direction="column" mt={16} rowGap={4}>
<Typography variant="xl">Other settings</Typography>
{settings && (settings.includes(ProfileLinks.PaymentMethod) || settings.includes(ProfileLinks.ProfileSetting)) && (
<Typography variant="xl">Other settings</Typography>
)}
<Stack direction="row" columnGap={4}>
{settings && settings.includes('profile_settings') && (
{settings && settings.includes(ProfileLinks.PaymentMethod) && (
<SimpleButton>
<Typography variant="md">Set a payment method</Typography>
</SimpleButton>
)}
{settings && settings.includes('payment_method') && (
{settings && settings.includes(ProfileLinks.ProfileSetting) && (
<SimpleButton>
<Typography variant="md">Go to account settings</Typography>
</SimpleButton>
Expand Down
32 changes: 8 additions & 24 deletions src/app/views/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,16 @@ export const Sidebar = () => {

const handleMutableSettings = (selected: boolean, type: string) => {
if (!selected) {
if (type === ProfileLinks.ProfileSetting) {
const newSettings = appState?.mutableSettings.filter((el: string) => el !== type);
appState?.setAppState((prev) => ({ ...prev, mutableSettings: newSettings }));
}
if (type === ProfileLinks.PaymentMethod) {
const newSettings = appState?.mutableSettings.filter((el: string) => el !== type);
appState?.setAppState((prev) => ({ ...prev, mutableSettings: newSettings }));
}
const newSettings = appState?.mutableSettings.filter((el: string) => el !== type);
appState?.setAppState((prev) => ({ ...prev, mutableSettings: newSettings }));
}
if (selected) {
if (type === ProfileLinks.ProfileSetting) {
appState?.setAppState((prev) => ({
...prev,
mutableSettings: appState?.mutableSettings.includes(type)
? appState?.mutableSettings
: [...appState?.mutableSettings, type],
}));
}
if (type === ProfileLinks.PaymentMethod) {
appState?.setAppState((prev) => ({
...prev,
mutableSettings: appState?.mutableSettings.includes(type)
? appState?.mutableSettings
: [...appState?.mutableSettings, type],
}));
}
appState?.setAppState((prev) => ({
...prev,
mutableSettings: appState?.mutableSettings.includes(type)
? appState?.mutableSettings
: [...appState?.mutableSettings, type],
}));
}
};

Expand Down

0 comments on commit d0ed649

Please sign in to comment.