-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add app archive support * gql * Tweak copy * Delete function archive button * AlertModal * Fix * Bring back function archive button * Simplify code * Make alert modal more similar to modal --------- Co-authored-by: Ana <anafilipadealmeida@gmail.com>
- Loading branch information
1 parent
04e72bd
commit ca0c540
Showing
15 changed files
with
298 additions
and
133 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...rganization-active)/(dashboard)/env/[environmentSlug]/apps/[externalID]/ArchiveButton.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,38 @@ | ||
import { useState } from 'react'; | ||
import { Button } from '@inngest/components/Button'; | ||
|
||
import { ArchiveModal } from './ArchiveModal'; | ||
|
||
type Props = { | ||
appID: string; | ||
disabled?: boolean; | ||
isArchived: boolean; | ||
}; | ||
|
||
export function ArchiveButton({ appID, disabled = false, isArchived }: Props) { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
|
||
let label = 'Archive'; | ||
if (isArchived) { | ||
label = 'Unarchive'; | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
appearance="outlined" | ||
btnAction={() => setIsModalVisible(true)} | ||
disabled={disabled} | ||
kind="danger" | ||
label={label} | ||
/> | ||
|
||
<ArchiveModal | ||
appID={appID} | ||
isArchived={isArchived} | ||
isOpen={isModalVisible} | ||
onClose={() => setIsModalVisible(false)} | ||
/> | ||
</> | ||
); | ||
} |
100 changes: 100 additions & 0 deletions
100
...organization-active)/(dashboard)/env/[environmentSlug]/apps/[externalID]/ArchiveModal.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,100 @@ | ||
import { useState } from 'react'; | ||
import { Alert } from '@inngest/components/Alert'; | ||
import { AlertModal } from '@inngest/components/Modal'; | ||
import { toast } from 'sonner'; | ||
import { useMutation } from 'urql'; | ||
|
||
import { graphql } from '@/gql'; | ||
|
||
type Props = { | ||
appID: string; | ||
isArchived: boolean; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
export function ArchiveModal({ appID, isArchived, isOpen, onClose }: Props) { | ||
const [error, setError] = useState<Error>(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [, archiveApp] = useMutation(ArchiveAppDocument); | ||
const [, unarchiveApp] = useMutation(UnarchiveAppDocument); | ||
|
||
async function onConfirm() { | ||
setIsLoading(true); | ||
try { | ||
let error; | ||
let message: string; | ||
if (isArchived) { | ||
error = (await unarchiveApp({ appID })).error; | ||
message = 'Unarchived app'; | ||
} else { | ||
error = (await archiveApp({ appID })).error; | ||
message = 'Archived app'; | ||
} | ||
if (error) { | ||
throw error; | ||
} | ||
setError(undefined); | ||
toast.success(message); | ||
onClose(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
setError(error); | ||
} else { | ||
setError(new Error('unknown error')); | ||
} | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
} | ||
|
||
return ( | ||
<AlertModal | ||
isLoading={isLoading} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
onSubmit={onConfirm} | ||
title={`Are you sure you want to ${isArchived ? 'unarchive' : 'archive'} this app?`} | ||
className="w-[600px]" | ||
> | ||
<ul className="list-inside list-disc p-6 pb-0"> | ||
{isArchived && ( | ||
<> | ||
<li>New function runs can trigger.</li> | ||
<li>You may re-archive at any time.</li> | ||
</> | ||
)} | ||
{!isArchived && ( | ||
<> | ||
<li>New function runs will not trigger.</li> | ||
<li>Existing function runs will continue until completion.</li> | ||
<li>Functions will still be visible, including their run history.</li> | ||
<li>You may unarchive at any time.</li> | ||
</> | ||
)} | ||
</ul> | ||
|
||
{error && ( | ||
<Alert className="mt-4" severity="error"> | ||
{error.message} | ||
</Alert> | ||
)} | ||
</AlertModal> | ||
); | ||
} | ||
|
||
const ArchiveAppDocument = graphql(` | ||
mutation AchiveApp($appID: UUID!) { | ||
archiveApp(id: $appID) { | ||
id | ||
} | ||
} | ||
`); | ||
|
||
const UnarchiveAppDocument = graphql(` | ||
mutation UnachiveApp($appID: UUID!) { | ||
unarchiveApp(id: $appID) { | ||
id | ||
} | ||
} | ||
`); |
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
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
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
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
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
Oops, something went wrong.