Skip to content

Commit

Permalink
Merge pull request #2452 from target/ts-ScheduleAssignedToList
Browse files Browse the repository at this point in the history
ui/schedules: convert ScheduleAssignedToList to typescript
  • Loading branch information
tony-tvu authored Jun 17, 2022
2 parents ed1457f + a49fff2 commit 7f03c45
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
38 changes: 0 additions & 38 deletions web/src/app/schedules/ScheduleAssignedToList.js

This file was deleted.

50 changes: 50 additions & 0 deletions web/src/app/schedules/ScheduleAssignedToList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import { useQuery, gql } from 'urql'
import FlatList from '../lists/FlatList'
import Card from '@mui/material/Card'
import Spinner from '../loading/components/Spinner'
import { GenericError } from '../error-pages'

const query = gql`
query ($id: ID!) {
schedule(id: $id) {
id
assignedTo {
id
type
name
}
}
}
`

export default function ScheduleAssignedToList(props: {
scheduleID: string
}): JSX.Element {
const [{ data, fetching, error }] = useQuery({
query,
variables: { id: props.scheduleID },
})

if (error) {
return <GenericError error={error.message} />
}

if (fetching && !data) {
return <Spinner />
}

return (
<Card sx={{ width: '100%' }}>
<FlatList
items={data.schedule.assignedTo.map(
(t: { name: string; id: string }) => ({
title: t.name,
url: `/escalation-policies/${t.id}`,
}),
)}
emptyMessage='This schedule is not assigned to any escalation policies.'
/>
</Card>
)
}

0 comments on commit 7f03c45

Please sign in to comment.