From b1a8cdf3e3288f6084592f583407ea89cebd5134 Mon Sep 17 00:00:00 2001 From: kumikokashii Date: Fri, 29 May 2020 16:48:37 -0700 Subject: [PATCH] feat(navbar): add shortcut icon to the create pages --- src/components/Navbar.tsx | 54 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 2283873055..dd56391e7e 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,11 +1,53 @@ import { Navbar as HospitalRunNavbar } from '@hospitalrun/components' import React from 'react' import { useTranslation } from 'react-i18next' +import { useSelector } from 'react-redux' import { useHistory } from 'react-router-dom' +import Permissions from '../model/Permissions' +import { RootState } from '../store' + const Navbar = () => { + const { permissions } = useSelector((state: RootState) => state.user) const { t } = useTranslation() const history = useHistory() + + const addPages = [ + { + permission: Permissions.WritePatients, + label: t('patients.newPatient'), + path: '/patients/new', + }, + { + permission: Permissions.WriteAppointments, + label: t('scheduling.appointments.new'), + path: '/appointments/new', + }, + { + permission: Permissions.RequestLab, + label: t('labs.requests.new'), + path: '/labs/new', + }, + { + permission: Permissions.ReportIncident, + label: t('incidents.reports.new'), + path: '/incidents/new', + }, + ] + + const addDropdownList: { type: string; label: string; onClick: () => void }[] = [] + addPages.forEach((page) => { + if (permissions.includes(page.permission)) { + addDropdownList.push({ + type: 'link', + label: page.label, + onClick: () => { + history.push(page.path) + }, + }) + } + }) + return ( { onClickButton: () => undefined, onChangeInput: () => undefined, }, + { + type: 'link-list-icon', + alignRight: true, + children: addDropdownList, + className: 'pl-4', + iconClassName: 'align-bottom', + label: 'Add', + name: 'add', + size: 'lg', + }, { type: 'link-list-icon', alignRight: true, @@ -112,7 +164,7 @@ const Navbar = () => { }, }, ], - className: 'pl-4', + className: 'pl-2', iconClassName: 'align-bottom', label: 'Patient', name: 'patient',