-
Notifications
You must be signed in to change notification settings - Fork 27
/
service-page-project-switcher.js
35 lines (32 loc) 路 1.13 KB
/
service-page-project-switcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React from 'react';
import { useParams } from 'react-router';
import styled from '@emotion/styled';
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
import ProjectSwitcher from '../project-switcher';
const Container = styled.div`
width: 200px;
text-align: left;
margin: 0 auto;
`;
export const ServicePageProjectSwitcher = () => {
const params = useParams();
const numberOfProjects = useApplicationContext(
context => context.user.projects.total
);
if (numberOfProjects === 0) return null;
return (
<Container>
<ProjectSwitcher
// In this case it's not necessary to check if the `projectKey` param
// is included in the list of projects. In such case
// the dropdown will still be rendered but no project will be selected.
// This is fine becase the user has still the possibility to "switch"
// to a project.
projectKey={params.projectKey}
total={numberOfProjects}
/>
</Container>
);
};
ServicePageProjectSwitcher.displayName = 'ServicePageProjectSwitcher';
export default ServicePageProjectSwitcher;