Skip to content

Commit

Permalink
🎁 WorkOrder Notifications (#1153)
Browse files Browse the repository at this point in the history
* Added notifications to workorder
  • Loading branch information
kjellhaaland authored Oct 21, 2024
1 parent b001927 commit 4c519bd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/workordersidesheet/src/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type { WorkOrderMaterial } from './workOrderMaterial';
export type { WorkOrderMccr } from './workOrderMccr';
export type { WorkOrderNotification } from './workOrderNotification';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type WorkOrderNotification = {
notificationNo: string;
type: string;
title: string;
status: string;
nextToSign: string;
notificationUrl: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
LinkCell,
MaterialTab,
MccrTab,
NotificationTab,
PackageStatus,
StatusCircle,
colorMap,
Expand Down Expand Up @@ -34,6 +35,7 @@ import { ModelViewerTab, TagOverlay } from '@cc-components/modelviewer';
import { useMaterial, useMccr } from '../utils-sidesheet';
import { DetailsTab } from './DetailsTab';
import { useGetEchoConfig } from '../utils-sidesheet/useGetEchoConfig';
import { useNotifications } from '../utils-sidesheet/useNotifications';

const viewerOptions = {
statusResolver: (status: string) => {
Expand All @@ -56,6 +58,12 @@ export const WorkorderSidesheet = (props: {
error: materialError,
} = useMaterial(props.id);

const {
data: notifications,
isFetching: isFetchingNotifications,
error: notificationsError,
} = useNotifications(props.id);

const {
data: modelConfig,
isFetching: isFetchingModelConfig,
Expand Down Expand Up @@ -164,6 +172,10 @@ export const WorkorderSidesheet = (props: {
<Tabs.Tab>
Material <TabTitle data={material} isLoading={isFetchingMaterial} />
</Tabs.Tab>
<Tabs.Tab>
Notifications
<TabTitle data={notifications} isLoading={isFetchingNotifications} />
</Tabs.Tab>
<Tabs.Tab>
3D <TabTitle data={modelConfig?.tags} isLoading={isFetchingModelConfig} />
</Tabs.Tab>
Expand All @@ -188,6 +200,13 @@ export const WorkorderSidesheet = (props: {
error={materialError as Error | null}
/>
</StyledPanel>
<StyledPanel>
<NotificationTab
notifications={notifications}
isFetching={isFetchingNotifications}
error={notificationsError}
/>
</StyledPanel>
<StyledPanel style={{ height: '100%' }}>
<ModelViewerTab
tagOverlay={tagsOverlay}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useContextId, useHttpClient } from '@cc-components/shared';
import { useQuery } from '@tanstack/react-query';
import { WorkOrderNotification } from '../types';

export const useNotifications = (workOrderId: string) => {
const client = useHttpClient();
const contextId = useContextId();

const { data, isFetching, error } = useQuery<WorkOrderNotification[], Error>({
queryKey: ['workOrder', workOrderId, 'notification'],
queryFn: async({ signal }) => {
const response = await client.fetch(`/api/contexts/${contextId}/work-orders/${workOrderId}/notifications`, { signal });

if (!response.ok) {
throw new Error('Failed to get notifications', { cause: response });
}

return response.json();
},
});

return { data, isFetching, error };
};

0 comments on commit 4c519bd

Please sign in to comment.