-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1991 from Infisical/daniel/leave-project
Feat: Leave Project
- Loading branch information
Showing
8 changed files
with
316 additions
and
12 deletions.
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
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
1 change: 1 addition & 0 deletions
1
backend/src/services/project-membership/project-membership-types.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
104 changes: 104 additions & 0 deletions
104
frontend/src/components/v2/LeaveProjectModal/LeaveProjectModal.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,104 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import { useToggle } from "@app/hooks"; | ||
|
||
import { Button } from "../Button"; | ||
import { FormControl } from "../FormControl"; | ||
import { Input } from "../Input"; | ||
import { Modal, ModalClose, ModalContent } from "../Modal"; | ||
|
||
type Props = { | ||
deleteKey: string; | ||
title: string; | ||
onLeaveApproved: () => Promise<void>; | ||
onClose?: () => void; | ||
onChange?: (isOpen: boolean) => void; | ||
isOpen?: boolean; | ||
subTitle?: string; | ||
buttonText?: string; | ||
}; | ||
|
||
export const LeaveProjectModal = ({ | ||
isOpen, | ||
onClose, | ||
onChange, | ||
deleteKey, | ||
onLeaveApproved, | ||
title, | ||
subTitle, | ||
buttonText = "Leave Project" | ||
}: Props): JSX.Element => { | ||
const [inputData, setInputData] = useState(""); | ||
const [isLoading, setIsLoading] = useToggle(); | ||
|
||
useEffect(() => { | ||
setInputData(""); | ||
}, [isOpen]); | ||
|
||
const onDelete = async () => { | ||
setIsLoading.on(); | ||
try { | ||
await onLeaveApproved(); | ||
} catch { | ||
setIsLoading.off(); | ||
} finally { | ||
setIsLoading.off(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onOpenChange={(isOpenState) => { | ||
setInputData(""); | ||
if (onChange) onChange(isOpenState); | ||
}} | ||
> | ||
<ModalContent | ||
title={title} | ||
subTitle={subTitle} | ||
footerContent={ | ||
<div className="mx-2 flex items-center"> | ||
<Button | ||
className="mr-4" | ||
colorSchema="danger" | ||
isDisabled={!(deleteKey === inputData) || isLoading} | ||
onClick={onDelete} | ||
isLoading={isLoading} | ||
> | ||
{buttonText} | ||
</Button> | ||
<ModalClose asChild> | ||
<Button variant="plain" colorSchema="secondary" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
</ModalClose>{" "} | ||
</div> | ||
} | ||
onClose={onClose} | ||
> | ||
<form | ||
onSubmit={(evt) => { | ||
evt.preventDefault(); | ||
if (deleteKey === inputData) onDelete(); | ||
}} | ||
> | ||
<FormControl | ||
label={ | ||
<div className="break-words pb-2 text-sm"> | ||
Type <span className="font-bold">{deleteKey}</span> to leave the project | ||
</div> | ||
} | ||
className="mb-0" | ||
> | ||
<Input | ||
value={inputData} | ||
onChange={(e) => setInputData(e.target.value)} | ||
placeholder="Type to confirm..." | ||
/> | ||
</FormControl> | ||
</form> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; |
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 @@ | ||
export { LeaveProjectModal } from "./LeaveProjectModal"; |
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.