Skip to content

Commit

Permalink
Merge pull request #564 from Studio-Yandex-Practicum/feature/issue-56…
Browse files Browse the repository at this point in the history
…2/hide&show-volunteers-button-settings

Feature/issue 562/hide&show volunteers button settings
  • Loading branch information
AntonZelinsky authored Sep 11, 2024
2 parents a86c3f2 + 233177d commit 6167e10
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/components/history-page/title/history-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import style from './history-title.module.css';
interface IHistoryTitle {
data: Festival
currentYear: number
showVolunteers: boolean
}

// TODO: TT заменить на локальное изображение
const imageUrl = 'https://s1.hostingkartinok.com/uploads/images/2021/12/fb0c8e1baf21b0ca306ee98a6678c0d8.png';

export const HistoryTitle: React.FC<IHistoryTitle> = ({ data, currentYear }) => {
export const HistoryTitle: React.FC<IHistoryTitle> = ({ data, currentYear, showVolunteers }) => {
const {
plays_count,
selected_plays_count,
Expand All @@ -33,7 +34,6 @@ export const HistoryTitle: React.FC<IHistoryTitle> = ({ data, currentYear }) =>
additional_links,
description
} = data;

const formatDate = (date: string) => new Date(date).toLocaleDateString('ru-Ru', {
timeZone: 'Europe/Moscow',
month: 'long',
Expand Down Expand Up @@ -61,15 +61,15 @@ export const HistoryTitle: React.FC<IHistoryTitle> = ({ data, currentYear }) =>
volunteers_count: {
count: volunteers_count,
title: 'волонтёров работали на фестивале',
buttonProps: {
buttonProps: showVolunteers ? {
href: urlVolonters,
iconPosition: 'right',
icon: <Icon
glyph="arrow-right"
width="100%"
height="100%"
/>
}
} : undefined
},
events_count: {
count: events_count,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/about-us/sponsors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Sponsors = (props: InferGetServerSidePropsType<typeof getServerSideProps>)
const permissions = settings?.permissions;

const router = useRouter();
if (permissions && !permissions.sponsors) {
if (permissions && !permissions.show_sponsors) {
router.replace('/about-us/404');
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/about-us/team/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Team = (props: InferGetServerSidePropsType<typeof getServerSideProps>) =>
const permissions = settings?.permissions;

const router = useRouter();
if (permissions && !permissions.team) {
if (permissions && !permissions.show_team) {
router.replace('/about-us/404');
}

Expand Down
13 changes: 10 additions & 3 deletions src/pages/history/[year].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HistoryItself } from 'components/history-page/itself';
import { HistoryTitle } from 'components/history-page/title';
import { SEO } from 'components/seo';
import { Menu } from 'components/ui/menu';
import { fetchSettings } from 'services/api/settings-adapter';
import { fetcher } from 'services/fetcher';
import { notFoundResult } from 'shared/constants/server-side-props';
import { InternalServerError } from 'shared/helpers/internal-server-error';
Expand All @@ -17,7 +18,8 @@ const History = (props: InferGetServerSidePropsType<typeof getServerSideProps>)
const {
years,
festival,
defaultYear
defaultYear,
showVolunteers,
} = props;

const menuRef = useHorizontalScroll<HTMLUListElement>();
Expand All @@ -43,6 +45,7 @@ const History = (props: InferGetServerSidePropsType<typeof getServerSideProps>)
<HistoryTitle
data={festival}
currentYear={defaultYear}
showVolunteers={showVolunteers}
/>
<HistoryItself data={itselfData}/>
</AppLayout>
Expand All @@ -68,7 +71,8 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R
? Number(params.year)
: years[0];

festival = await fetcher<Festival>(`/info/festivals/${defaultYear}/`);
festival = await fetcher<Festival>(`/info/festivals/${defaultYear}/`);

} catch ({ statusCode }) {
switch (statusCode) {
case 404:
Expand All @@ -77,12 +81,15 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R
throw new InternalServerError();
}
}

const settings = await fetchSettings(); // Semicolon added
const showVolunteers = settings.permissions.show_volunteers;

return {
props: {
festival,
years,
defaultYear,
showVolunteers,
},
};
};
5 changes: 3 additions & 2 deletions src/services/api/settings-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ const mapDTOToSettings = (dto: SettingsDTO): Settings => ({
title: project.title,
})),
permissions: {
team: dto.show_team,
sponsors: dto.show_sponsors,
show_team: dto.show_team,
show_volunteers: dto.show_volunteers,
show_sponsors: dto.show_sponsors,
mission: true,
'about-us': true,
}
Expand Down

0 comments on commit 6167e10

Please sign in to comment.