Skip to content

Commit

Permalink
Top Bar and Kitchen Outcomes Data Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
roshanbellary committed Dec 22, 2024
1 parent b7fdc6e commit 7d98451
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
39 changes: 36 additions & 3 deletions client/src/components/Topbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
AppBar,
Toolbar,
Expand All @@ -8,7 +8,7 @@ import {
MenuItem,
} from '@mui/material';
import { useLocation, useNavigate } from 'react-router-dom';
import { postData } from '../util/api';
import { getData, postData } from '../util/api';

const getPageTitle = (pathname: string): string => {
switch (pathname) {
Expand Down Expand Up @@ -43,7 +43,8 @@ function Topbar({ email }: { email: string }) {
const location = useLocation();
const navigate = useNavigate();
const pageTitle = getPageTitle(location.pathname);

const [orgName, setOrgName] = useState<string | null>(null);
const [orgId, setOrgId] = useState<string | null>(null);
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);

const handleMenuOpen = (event: React.MouseEvent<HTMLElement>) => {
Expand All @@ -58,6 +59,35 @@ function Topbar({ email }: { email: string }) {
postData('auth/logout');
navigate('/login');
};
useEffect(() => {
const getUserOrganizationId = async () => {
try {
const response = await getData(`auth/organization/${email}`);
const orgSetId = await response.data;
setOrgId(orgSetId);
} catch (e) {
console.error(e);
setOrgName(null);
setOrgId(null);
}
};
const getUserOrganizationName = async () => {
try {
if (orgId) {
const response = await getData(
`organization/organization/name/${orgId}`,
);
const orgSetName = await response.data;
setOrgName(orgSetName.organizationName);
}
} catch (e) {
console.error(e);
setOrgName(null);
}
};
getUserOrganizationId();
getUserOrganizationName();
}, [email, orgId]);

return (
<AppBar
Expand All @@ -81,6 +111,9 @@ function Topbar({ email }: { email: string }) {
onClose={handleMenuClose}
>
<MenuItem disabled>{email}</MenuItem>
<MenuItem disabled>
Organization: {orgName || 'None Assigned'}
</MenuItem>
<MenuItem onClick={handleLogout}>Logout</MenuItem>
</Menu>
</Toolbar>
Expand Down
1 change: 1 addition & 0 deletions server/src/models/kitchen.outcomes.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ interface IKitchenOutcomes extends mongoose.Document {
const KitchenOutcomes = mongoose.model<IKitchenOutcomes>(
'KitchenOutcomes',
KitchenOutcomesSchema,
'kitchenoutcomesuploadtest',
);

export { IKitchenOutcomes, KitchenOutcomes };
2 changes: 1 addition & 1 deletion server/src/services/kitchen.outcomes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getOneKitchenOutcomes = async (year: Date, orgId: string) => {
orgId,
year: {
$gte: startDate,
$lt: endDate,
$lte: endDate,
},
}).exec();
console.log(startDate);
Expand Down

0 comments on commit 7d98451

Please sign in to comment.