-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat(console): delete app modal checks custom domain config #2373
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8ed8c11
chore(console): refactor delete app modal form into a component
szkl 053a743
chore(console): move custom domain schema definition
szkl d489cd7
chore(console): prevent the delete button displaying a saved toast
szkl fe9a37a
feat(console): delete app modal checks custom domain config
szkl 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 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,4 +1,6 @@ | ||
import React, { useState } from 'react' | ||
import { useState } from 'react' | ||
import { Link, useFetcher } from '@remix-run/react' | ||
import type { FetcherWithComponents } from '@remix-run/react' | ||
|
||
import { Button } from '@proofzero/design-system/src/atoms/buttons/Button' | ||
import { Modal } from '@proofzero/design-system/src/molecules/modal/Modal' | ||
|
@@ -8,29 +10,30 @@ import dangerVector from '../../images/danger.svg' | |
import { Input } from '@proofzero/design-system/src/atoms/form/Input' | ||
import { RiLoader5Fill } from 'react-icons/ri' | ||
|
||
import type { appDetailsProps } from '~/types' | ||
|
||
export type DeleteAppModalProps = { | ||
clientId: string | ||
appName: string | ||
appDetails: appDetailsProps | ||
isOpen: boolean | ||
deleteAppCallback: (app: any) => void | ||
deleteAppCallback: (state: boolean) => unknown | ||
} | ||
|
||
export const DeleteAppModal = ({ | ||
clientId, | ||
appName, | ||
appDetails, | ||
isOpen, | ||
deleteAppCallback, | ||
}: DeleteAppModalProps) => { | ||
const [isAppNameMatches, setAppNameMatches] = useState(false) | ||
const [isSubmitting, setIsSubmitting] = useState(false) | ||
const fetcher = useFetcher() | ||
const [hasCustomDomain] = useState(!Boolean(appDetails.customDomain)) | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
closable={!isSubmitting} | ||
closable={fetcher.state !== 'submitting'} | ||
handleClose={() => deleteAppCallback(false)} | ||
> | ||
<div | ||
className={`w-[62vw] rounded-lg bg-white px-4 pb-4 | ||
className={`w-[48vw] rounded-lg bg-white px-4 pb-4 | ||
text-left transition-all sm:px-6 sm:pb-6 overflow-y-auto flex items-start space-x-4`} | ||
> | ||
<img src={dangerVector} /> | ||
|
@@ -40,62 +43,98 @@ export const DeleteAppModal = ({ | |
Delete Application | ||
</Text> | ||
|
||
<form | ||
method="post" | ||
action="/apps/delete" | ||
onSubmit={() => { | ||
setIsSubmitting(true) | ||
}} | ||
> | ||
<section className="mb-4"> | ||
<Text size="sm" weight="normal" className="text-gray-500 my-3"> | ||
Are you sure you want to delete <b>{appName}</b> app? This | ||
action cannot be undone once confirmed. | ||
</Text> | ||
<Text size="sm" weight="normal" className="text-gray-500 my-3"> | ||
Confirm you want to delete this application by typing its name | ||
below. | ||
</Text> | ||
<Input | ||
id="client_name" | ||
label="Application Name" | ||
placeholder="My application" | ||
required | ||
className="mb-12" | ||
onChange={(e) => { | ||
setAppNameMatches(appName === e?.target?.value) | ||
}} | ||
/> | ||
</section> | ||
<input type="hidden" name="clientId" value={clientId} /> | ||
|
||
<div className="flex justify-end items-center space-x-3"> | ||
<Button | ||
btnType="secondary-alt" | ||
disabled={isSubmitting} | ||
onClick={() => deleteAppCallback(false)} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
disabled={!isAppNameMatches || isSubmitting} | ||
type="submit" | ||
btnType="dangerous" | ||
className={ | ||
isSubmitting | ||
? 'flex items-center justify-between transition' | ||
: '' | ||
} | ||
> | ||
{isSubmitting && ( | ||
<RiLoader5Fill className="animate-spin" size={22} /> | ||
)} | ||
Delete | ||
</Button> | ||
</div> | ||
</form> | ||
{hasCustomDomain && ( | ||
<HasCustomDomain appDetails={appDetails}></HasCustomDomain> | ||
)} | ||
{!hasCustomDomain && ( | ||
<DeleteModalAppForm | ||
fetcher={fetcher} | ||
appDetails={appDetails} | ||
callback={deleteAppCallback} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
</Modal> | ||
) | ||
} | ||
|
||
type DeleteModalAppFormProps = { | ||
fetcher: FetcherWithComponents<any> | ||
appDetails: appDetailsProps | ||
callback: (state: boolean) => unknown | ||
} | ||
|
||
const DeleteModalAppForm = ({ | ||
fetcher, | ||
appDetails, | ||
callback, | ||
}: DeleteModalAppFormProps) => { | ||
const [isAppNameMatches, setAppNameMatches] = useState(false) | ||
return ( | ||
<fetcher.Form method="post" action="/apps/delete" reloadDocument={true}> | ||
<section className="mb-4"> | ||
<Text size="sm" weight="normal" className="text-gray-500 my-3"> | ||
Are you sure you want to delete <b>{appDetails.app.name}</b> app? This | ||
action cannot be undone once confirmed. | ||
</Text> | ||
<Text size="sm" weight="normal" className="text-gray-500 my-3"> | ||
Confirm you want to delete this application by typing its name below. | ||
</Text> | ||
<Input | ||
id="client_name" | ||
label="Application Name" | ||
placeholder="My application" | ||
required | ||
className="mb-12" | ||
onChange={(e) => | ||
setAppNameMatches(appDetails.app.name === e?.target?.value) | ||
} | ||
/> | ||
</section> | ||
<input type="hidden" name="clientId" value={appDetails.clientId} /> | ||
|
||
<div className="flex justify-end items-center space-x-3"> | ||
<Button | ||
btnType="secondary-alt" | ||
disabled={fetcher.state === 'submitting'} | ||
onClick={() => callback(false)} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
disabled={!isAppNameMatches || fetcher.state === 'submitting'} | ||
type="submit" | ||
btnType="dangerous" | ||
className={ | ||
fetcher.state === 'submitting' | ||
? 'flex items-center justify-between transition' | ||
: '' | ||
} | ||
> | ||
{fetcher.state === 'submitting' && ( | ||
<RiLoader5Fill className="animate-spin" size={22} /> | ||
)} | ||
Delete | ||
</Button> | ||
</div> | ||
</fetcher.Form> | ||
) | ||
} | ||
|
||
type HasCustomDomainProps = { | ||
appDetails: appDetailsProps | ||
} | ||
|
||
const HasCustomDomain = ({ appDetails }: HasCustomDomainProps) => ( | ||
<section className="flex flex-col mb-4"> | ||
<Text size="sm" weight="normal" className="text-gray-500 my-3"> | ||
This application has a custom domain configured. You need to delete it | ||
before you can delete the application. | ||
</Text> | ||
|
||
<Link to={`/apps/${appDetails.clientId}/domain-wip`} className="self-end"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be set to final route as part of #2374 |
||
<Button btnType="secondary-alt">Go to Custom Domain</Button> | ||
</Link> | ||
</section> | ||
) |
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.
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.
The form inside DeleteModalAppForm makes a
post
to /apps/delete. This API route also needs to do this check on the backend and throw an error.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.
Done.