-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
8 changes: 8 additions & 0 deletions
8
libs/workordersidesheet/src/lib/types/workOrderNotification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libs/workordersidesheet/src/lib/utils-sidesheet/useNotifications.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |