-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
148 additions
and
13 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
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
20 changes: 20 additions & 0 deletions
20
...es/common/providers/CommonData/components/DeleteCommonModal/DeleteCommonModal.module.scss
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,20 @@ | ||
@import "../../../../../../constants"; | ||
|
||
.modal { | ||
max-width: 30rem; | ||
} | ||
|
||
.buttonsWrapper { | ||
display: flex; | ||
width: fit-content; | ||
margin-left: auto; | ||
margin-top: 3.25rem; | ||
} | ||
|
||
.deleteButton { | ||
margin-left: 1.375rem; | ||
} | ||
|
||
.error { | ||
font-size: $xsmall; | ||
} |
78 changes: 78 additions & 0 deletions
78
src/pages/common/providers/CommonData/components/DeleteCommonModal/DeleteCommonModal.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,78 @@ | ||
import React, { FC, useState } from "react"; | ||
import { CommonMemberEventEmitter } from "@/events"; | ||
import { CommonService } from "@/services"; | ||
import { Modal } from "@/shared/components"; | ||
import { ErrorText } from "@/shared/components/Form"; | ||
import { Button, ButtonVariant } from "@/shared/ui-kit"; | ||
import { emptyFunction } from "@/shared/utils"; | ||
import styles from "./DeleteCommonModal.module.scss"; | ||
|
||
interface DeleteCommonModalProps { | ||
commonId: string; | ||
commonName: string; | ||
isSpace: boolean; | ||
isShowing: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
const DeleteCommonModal: FC<DeleteCommonModalProps> = (props) => { | ||
const { isShowing, onClose, commonName, isSpace, commonId } = props; | ||
const [isDeleting, setIsDeleting] = useState(false); | ||
const [errorText, setErrorText] = useState(""); | ||
const entityType = isSpace ? "space" : "common"; | ||
|
||
const handleLeave = async () => { | ||
setIsDeleting(true); | ||
setErrorText(""); | ||
|
||
try { | ||
await CommonService.deleteCommon(commonId); | ||
// CommonMemberEventEmitter.emit( | ||
// CommonMemberEvent.Reset, | ||
// commonId, | ||
// commonMemberId, | ||
// ); | ||
setIsDeleting(false); | ||
onClose(); | ||
} catch (error) { | ||
setErrorText("Something went wrong"); | ||
setIsDeleting(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal | ||
className={styles.modal} | ||
title={`Delete ${commonName} ${entityType}`} | ||
isShowing={isShowing} | ||
onClose={isDeleting ? emptyFunction : onClose} | ||
> | ||
<div> | ||
Deleting a {entityType} is irreversible and will delete all of its | ||
content. Are you sure you want to continue? | ||
<div className={styles.buttonsWrapper}> | ||
<Button | ||
variant={ButtonVariant.OutlineDarkPink} | ||
onClick={onClose} | ||
disabled={isDeleting} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
className={styles.deleteButton} | ||
variant={ButtonVariant.PrimaryPink} | ||
onClick={handleLeave} | ||
disabled={isDeleting} | ||
> | ||
Delete {entityType} | ||
</Button> | ||
</div> | ||
{errorText && ( | ||
<ErrorText className={styles.error}>{errorText}</ErrorText> | ||
)} | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DeleteCommonModal; |
1 change: 1 addition & 0 deletions
1
src/pages/common/providers/CommonData/components/DeleteCommonModal/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as DeleteCommonModal } from "./DeleteCommonModal"; |
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,3 +1,4 @@ | ||
export * from "./useJoinCircleModal"; | ||
export * from "./useLeaveCircleModal"; | ||
export * from "./useProposalCreationModal"; | ||
export * from "./useDeleteCommonModal"; |
11 changes: 11 additions & 0 deletions
11
src/pages/common/providers/CommonData/hooks/useDeleteCommonModal.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useModal } from "@/shared/hooks"; | ||
|
||
export const useDeleteCommonModal = () => { | ||
const { isShowing, onOpen, onClose } = useModal(false); | ||
|
||
return { | ||
isDeleteCommonModalOpen: isShowing, | ||
onDeleteCommonModalClose: onClose, | ||
onCommonDelete: onOpen, | ||
}; | ||
}; |
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