-
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.
Added workorder description components (#1158)
- Loading branch information
1 parent
4c519bd
commit e8ee77f
Showing
5 changed files
with
105 additions
and
1 deletion.
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,3 +1,4 @@ | ||
export type { WorkOrderMaterial } from './workOrderMaterial'; | ||
export type { WorkOrderMccr } from './workOrderMccr'; | ||
export type { WorkOrderNotification } from './workOrderNotification'; | ||
export type { WorkOrderNotification } from './workOrderNotification'; | ||
export type { WorkOrderDescription } from './workOrderDescription'; |
3 changes: 3 additions & 0 deletions
3
libs/workordersidesheet/src/lib/types/workOrderDescription.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,3 @@ | ||
export type WorkOrderDescription = { | ||
description: 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
72 changes: 72 additions & 0 deletions
72
libs/workordersidesheet/src/lib/ui-sidesheet/WorkorderDescription.tsx
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,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 ( | ||
<StyledTabContent> | ||
<h3>Description</h3> | ||
|
||
{isFetching && ( | ||
<NoResourceData> | ||
<Progress.Circular /> | ||
<InfoText>Fetching description</InfoText> | ||
</NoResourceData> | ||
)} | ||
|
||
{error && ( | ||
<NoResourceData> | ||
<Icon | ||
name="error_outlined" | ||
size={40} | ||
color={tokens.colors.interactive.primary__resting.hsla} | ||
/> | ||
<InfoText>Failed to load description</InfoText> | ||
</NoResourceData> | ||
)} | ||
|
||
{!isFetching && data && !data.description && ( | ||
<NoResourceData> | ||
<Icon | ||
name="info_circle" | ||
size={40} | ||
color={tokens.colors.interactive.primary__resting.hsla} | ||
/> | ||
<InfoText>No description</InfoText> | ||
</NoResourceData> | ||
)} | ||
|
||
{!isFetching && data && <StyledDescription>{data.description}</StyledDescription>} | ||
</StyledTabContent> | ||
); | ||
}; | ||
|
||
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; | ||
`; |
23 changes: 23 additions & 0 deletions
23
libs/workordersidesheet/src/lib/utils-sidesheet/useWorkOrderDescription.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 { WorkOrderDescription } from '../types'; | ||
|
||
export const useWorkOrderDescription = (workOrderId: string) => { | ||
const client = useHttpClient(); | ||
const contextId = useContextId(); | ||
|
||
const { data, isFetching, error } = useQuery<WorkOrderDescription, Error>({ | ||
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 }; | ||
}; |