-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
3 changed files
with
67 additions
and
23 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
62 changes: 51 additions & 11 deletions
62
apps/dashboard/src/components/integrations/components/modals/delete-integration-modal.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 |
---|---|---|
@@ -1,30 +1,70 @@ | ||
import { ConfirmationModal } from '@/components/confirmation-modal'; | ||
import { SelectPrimaryIntegrationModal } from './select-primary-integration-modal'; | ||
import { IIntegration } from '@novu/shared'; | ||
import { useState } from 'react'; | ||
|
||
export type DeleteIntegrationModalProps = { | ||
isOpen: boolean; | ||
onOpenChange: (open: boolean) => void; | ||
onConfirm: () => void; | ||
onConfirm: (newPrimaryIntegrationId?: string) => void; | ||
isPrimary?: boolean; | ||
otherIntegrations?: IIntegration[]; | ||
}; | ||
|
||
export function DeleteIntegrationModal({ isOpen, onOpenChange, onConfirm, isPrimary }: DeleteIntegrationModalProps) { | ||
export function DeleteIntegrationModal({ | ||
isOpen, | ||
onOpenChange, | ||
onConfirm, | ||
isPrimary, | ||
otherIntegrations = [], | ||
}: DeleteIntegrationModalProps) { | ||
const [isSelectPrimaryModalOpen, setIsSelectPrimaryModalOpen] = useState(false); | ||
const hasOtherIntegrations = otherIntegrations.length > 0; | ||
|
||
const description = isPrimary ? ( | ||
<> | ||
<p>Are you sure you want to delete this primary integration?</p> | ||
<p>This will disable the channel until you set up a new integration.</p> | ||
<p> | ||
{hasOtherIntegrations | ||
? 'You will need to select a new primary integration for this channel.' | ||
: 'This will disable the channel until you set up a new integration.'} | ||
</p> | ||
</> | ||
) : ( | ||
<p>Are you sure you want to delete this integration?</p> | ||
); | ||
|
||
const handleConfirm = () => { | ||
if (isPrimary && hasOtherIntegrations) { | ||
setIsSelectPrimaryModalOpen(true); | ||
|
||
return; | ||
} | ||
|
||
onConfirm(); | ||
}; | ||
|
||
return ( | ||
<ConfirmationModal | ||
open={isOpen} | ||
onOpenChange={onOpenChange} | ||
onConfirm={onConfirm} | ||
title={`Delete ${isPrimary ? 'Primary ' : ''}Integration`} | ||
description={description} | ||
confirmButtonText="Delete Integration" | ||
/> | ||
<> | ||
<ConfirmationModal | ||
open={isOpen} | ||
onOpenChange={onOpenChange} | ||
onConfirm={handleConfirm} | ||
title={`Delete ${isPrimary ? 'Primary ' : ''}Integration`} | ||
description={description} | ||
confirmButtonText="Delete Integration" | ||
/> | ||
|
||
<SelectPrimaryIntegrationModal | ||
isOpen={isSelectPrimaryModalOpen} | ||
onOpenChange={setIsSelectPrimaryModalOpen} | ||
onConfirm={(newPrimaryIntegrationId) => { | ||
setIsSelectPrimaryModalOpen(false); | ||
onConfirm(newPrimaryIntegrationId); | ||
}} | ||
otherIntegrations={otherIntegrations} | ||
mode="select" | ||
/> | ||
</> | ||
); | ||
} |
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