Skip to content

Commit

Permalink
feat: added pinned announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardik-hi committed Aug 5, 2022
1 parent 62ac427 commit 3b577f0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"LAST_DAY": "Last Day",
"PRINCIPAL": "Principal",
"TEACHER": "Teacher"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"LAST_DAY": "पिचले एक दिन",
"PRINCIPAL": "प्रमुख",
"TEACHER": "शिक्षक"
}
}
37 changes: 18 additions & 19 deletions packages/common-lib/src/components/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Center, NativeBaseProvider } from 'native-base'
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'
import { eventBus } from '../services/EventBus'
import Loading from './Loading'
import { getAnnouncementsSet } from '../services/announcementsRegistryService'

function AppShell({
theme,
Expand Down Expand Up @@ -59,23 +60,17 @@ function AppShell({
//TODO: integrate with API call to fetch whitelisted modules
const pinnedAnnouncementsWhitelist = ['announcements']
//TODO: integrate with API call to fetch pinned announcements
const [pinnedAnnouncementsData, setPinnedAnnouncementsData] = useState([])

useEffect(() => {
if (!pinnedAnnouncementsWhitelist.some((val: string) => val === appName))
return

getAnnouncementsSet({ isPinned: true, status: 'published' }).then((res) => {
setPinnedAnnouncementsData(res.data)
})
}, [])

const pinnedAnnouncementsData = !pinnedAnnouncementsWhitelist.some(
(val: string) => val === appName
)
? undefined
: [
{
data: 'Shiksha V2.0 Is Live! 🚀🎉',
color: 'green.100',
isDismissable: true
},
{
data: 'Students should not stand on road outside school during monsoon',
color: 'amber.100',
isDismissable: false
}
]
useEffect(() => {
const subscription = eventBus.subscribe('AUTH', (data, envelop) => {
if ((data.eventType = 'LOGIN_SUCCESS')) {
Expand Down Expand Up @@ -111,9 +106,13 @@ function AppShell({
key={index}
path={item.path}
element={
<item.component
{...{ footerLinks, appName, pinnedAnnouncementsData }}
/>
pinnedAnnouncementsData?.length > 0 ? (
<item.component
{...{ footerLinks, appName, pinnedAnnouncementsData }}
/>
) : (
<item.component {...{ footerLinks, appName }} />
)
}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export default function PinnedAnnouncements({ _pinnedAnnouncementsData }: any) {
<VStack space='2'>
{pinnedData?.map((val: any, index: number) => (
<HStack
bg={val.color}
bg='green.100'
space='4'
px='5'
py={val.isDismissable ? '3.5' : '5'}
py={val?.pinnedAnnouncementProperties?.isDismissable ? '3.5' : '5'}
key={index}
alignItems='center'
justifyContent='flex-start'
Expand All @@ -40,7 +40,7 @@ export default function PinnedAnnouncements({ _pinnedAnnouncementsData }: any) {
<BodyMedium>{val.data}</BodyMedium>
</HStack>

{val.isDismissable ? (
{val?.pinnedAnnouncementProperties?.isDismissable ? (
<IconByName
_icon={{ size: '20' }}
name='CloseLineIcon'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ export const getAnnouncementsSet = async (params = {}, header = {}) => {
headers
})
if (result.data.data) {
console.log(result);
return result.data.data;
console.log(result)
return result.data.data
} else {
return {}
}
}




0 comments on commit 3b577f0

Please sign in to comment.