diff --git a/libs/workordersidesheet/src/lib/types/index.ts b/libs/workordersidesheet/src/lib/types/index.ts index 32729924..9acf9b3c 100644 --- a/libs/workordersidesheet/src/lib/types/index.ts +++ b/libs/workordersidesheet/src/lib/types/index.ts @@ -1,3 +1,4 @@ export type { WorkOrderMaterial } from './workOrderMaterial'; export type { WorkOrderMccr } from './workOrderMccr'; -export type { WorkOrderNotification } from './workOrderNotification'; \ No newline at end of file +export type { WorkOrderNotification } from './workOrderNotification'; +export type { WorkOrderDescription } from './workOrderDescription'; \ No newline at end of file diff --git a/libs/workordersidesheet/src/lib/types/workOrderDescription.ts b/libs/workordersidesheet/src/lib/types/workOrderDescription.ts new file mode 100644 index 00000000..eeb2b2c0 --- /dev/null +++ b/libs/workordersidesheet/src/lib/types/workOrderDescription.ts @@ -0,0 +1,3 @@ +export type WorkOrderDescription = { + description: string; +} \ No newline at end of file diff --git a/libs/workordersidesheet/src/lib/ui-sidesheet/DetailsTab.tsx b/libs/workordersidesheet/src/lib/ui-sidesheet/DetailsTab.tsx index 660fb61a..90048c0b 100644 --- a/libs/workordersidesheet/src/lib/ui-sidesheet/DetailsTab.tsx +++ b/libs/workordersidesheet/src/lib/ui-sidesheet/DetailsTab.tsx @@ -8,11 +8,15 @@ import { } from '@cc-components/shared'; import { getWoStatus, WorkOrder } from '@cc-components/workordershared'; +import { WorkOrderDescription } from './WorkorderDescription'; + type DetailsTabProps = { workOrder: WorkOrder | undefined; }; + export const DetailsTab = ({ workOrder }: DetailsTabProps): JSX.Element | null => { if (!workOrder) return null; + return (

Details

@@ -119,6 +123,7 @@ export const DetailsTab = ({ workOrder }: DetailsTabProps): JSX.Element | null = +
); }; diff --git a/libs/workordersidesheet/src/lib/ui-sidesheet/WorkorderDescription.tsx b/libs/workordersidesheet/src/lib/ui-sidesheet/WorkorderDescription.tsx new file mode 100644 index 00000000..58eacf00 --- /dev/null +++ b/libs/workordersidesheet/src/lib/ui-sidesheet/WorkorderDescription.tsx @@ -0,0 +1,72 @@ +import styled from 'styled-components'; +import { Icon, Progress } from '@equinor/eds-core-react'; +import { tokens } from '@equinor/eds-tokens'; + +import { StyledTabContent } from '@cc-components/shared'; + +import { useWorkOrderDescription } from '../utils-sidesheet/useWorkOrderDescription'; + +type WorkOrderDescriptionProps = { + workOrderId: string; +}; + +export const WorkOrderDescription = (props: WorkOrderDescriptionProps): JSX.Element => { + const { workOrderId } = props; + + const { data, isFetching, error } = useWorkOrderDescription(workOrderId); + + return ( + +

Description

+ + {isFetching && ( + + + Fetching description + + )} + + {error && ( + + + Failed to load description + + )} + + {!isFetching && data && !data.description && ( + + + No description + + )} + + {!isFetching && data && {data.description}} +
+ ); +}; + +const StyledDescription = styled.p` + padding: 0rem 1rem; +`; + +export const NoResourceData = styled.div` + text-align: center; + padding: 20px; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + gap: 10px; +`; + +export const InfoText = styled.h3` + margin: 0; +`; diff --git a/libs/workordersidesheet/src/lib/utils-sidesheet/useWorkOrderDescription.ts b/libs/workordersidesheet/src/lib/utils-sidesheet/useWorkOrderDescription.ts new file mode 100644 index 00000000..135c5f3f --- /dev/null +++ b/libs/workordersidesheet/src/lib/utils-sidesheet/useWorkOrderDescription.ts @@ -0,0 +1,23 @@ +import { useContextId, useHttpClient } from '@cc-components/shared'; +import { useQuery } from '@tanstack/react-query'; +import { WorkOrderDescription } from '../types'; + +export const useWorkOrderDescription = (workOrderId: string) => { + const client = useHttpClient(); + const contextId = useContextId(); + + const { data, isFetching, error } = useQuery({ + queryKey: ['workOrder', workOrderId, 'description'], + queryFn: async({ signal }) => { + const response = await client.fetch(`/api/contexts/${contextId}/work-orders/${workOrderId}/description`, { signal }); + + if (!response.ok) { + throw new Error('Failed to get notifications', { cause: response }); + } + + return response.json(); + }, + }); + + return { data, isFetching, error }; +};