-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui/schedules: convert ScheduleOverrideDeleteDialog to ts and use urql #2461
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3a4908
convert to typescript
tony-tvu 7b2f8bb
Merge branch 'master' of https://github.com/target/goalert into ts-Sc…
tony-tvu fb62ac2
resolve destructuring on null object issue
tony-tvu b6f93a1
make empty string if null
tony-tvu 14efecc
refactor assignments
tony-tvu 74d049a
make onClose required
tony-tvu ebceb5c
Merge branch 'master' of https://github.com/target/goalert into ts-Sc…
tony-tvu 4ded039
use urql
tony-tvu 6a48ae3
fix nonFieldErrors input param
tony-tvu 27c3057
add error check
KatieMSB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,101 @@ | ||
import React from 'react' | ||
|
||
import { gql, useQuery, useMutation } from 'urql' | ||
import { nonFieldErrors } from '../util/errutil' | ||
import { Typography } from '@mui/material' | ||
import FormDialog from '../dialogs/FormDialog' | ||
import { useURLParam } from '../actions/hooks' | ||
import { formatOverrideTime } from './util' | ||
import { GenericError } from '../error-pages' | ||
import Spinner from '../loading/components/Spinner' | ||
|
||
const query = gql` | ||
query ($id: ID!) { | ||
userOverride(id: $id) { | ||
id | ||
start | ||
end | ||
addUser { | ||
id | ||
name | ||
} | ||
removeUser { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
const mutation = gql` | ||
mutation delete($input: [TargetInput!]!) { | ||
deleteAll(input: $input) | ||
} | ||
` | ||
|
||
export default function ScheduleOverrideDeleteDialog(props: { | ||
overrideID: string | ||
onClose: () => void | ||
}): JSX.Element { | ||
const [zone] = useURLParam('tz', 'local') | ||
|
||
const [{ data, fetching, error }] = useQuery({ | ||
query, | ||
variables: { id: props.overrideID }, | ||
}) | ||
|
||
const [deleteOverrideStatus, deleteOverride] = useMutation(mutation) | ||
|
||
if (error) { | ||
return <GenericError error={error.message} /> | ||
} | ||
|
||
if (fetching && !data) { | ||
return <Spinner /> | ||
} | ||
|
||
const addUser = data.userOverride.addUser ? data.userOverride.addUser : '' | ||
const removeUser = data.userOverride.removeUser | ||
? data.userOverride.removeUser | ||
: '' | ||
const start = data.userOverride.start ? data.userOverride.start : '' | ||
const end = data.userOverride.end ? data.userOverride.end : '' | ||
|
||
const isReplace = addUser && removeUser | ||
const verb = addUser ? 'Added' : 'Removed' | ||
const time = formatOverrideTime(start, end, zone) | ||
|
||
const caption = isReplace | ||
? `Replaced ${removeUser.name} from ${time}` | ||
: `${verb} from ${time}` | ||
|
||
return ( | ||
<FormDialog | ||
title='Are you sure?' | ||
confirm | ||
subTitle={`This will delete the override for: ${ | ||
addUser ? addUser.name : removeUser.name | ||
}`} | ||
loading={deleteOverrideStatus.fetching} | ||
errors={nonFieldErrors(deleteOverrideStatus.error)} | ||
onClose={props.onClose} | ||
onSubmit={() => | ||
deleteOverride( | ||
{ | ||
input: [ | ||
{ | ||
type: 'userOverride', | ||
id: props.overrideID, | ||
}, | ||
], | ||
}, | ||
{ additionalTypenames: ['UserOverride'] }, | ||
).then((res) => { | ||
if (res.error) return | ||
props.onClose() | ||
}) | ||
} | ||
form={<Typography variant='caption'>{caption}</Typography>} | ||
/> | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a suggestion