-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
fix: No option to install/disconnect app from app detail page #17997
Open
asadath1395
wants to merge
22
commits into
calcom:main
Choose a base branch
from
asadath1395:fix-install-disconnect-app-details-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+233
−78
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1e03777
fix: No option to install/disconnect app from app detail page
asadath1395 2a4e4f6
Merge with upstream
asadath1395 1cdd908
Fix types
asadath1395 2bb744f
Merge branch 'main' into fix-install-disconnect-app-details-page
asadath1395 9aab30c
Merge with upstream and resolve conflicts
asadath1395 fd1e41d
Merge branch 'fix-install-disconnect-app-details-page' of https://git…
asadath1395 283b2bd
Merge branch 'main' into fix-install-disconnect-app-details-page
asadath1395 764b83a
Merge branch 'main' into fix-install-disconnect-app-details-page
asadath1395 5838426
Merge branch 'main' into fix-install-disconnect-app-details-page
asadath1395 2f9888e
fix: Install button showing up even after it is installed for all tar…
hariombalhara 454ffa2
chore: Simplified installOrDisconnectAppButton making it easy to read
hariombalhara 06e33d5
Merge branch 'main' into fix-install-disconnect-app-details-page
asadath1395 6f4e90a
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich 81c8640
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich e58568b
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich d6e67dd
Merge branch 'main' into fix-install-disconnect-app-details-page
anikdhabal 9992d8b
Merge branch 'main' into fix-install-disconnect-app-details-page
asadath1395 5c05bd5
Merge branch 'main' into fix-install-disconnect-app-details-page
keithwillcode 19b0bff
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich 568f5ee
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich ce8a7af
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich 3a74ccd
Merge branch 'main' into fix-install-disconnect-app-details-page
PeerRich 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ import type { App as AppType } from "@calcom/types/App"; | |
import { Badge, Button, Icon, SkeletonButton, SkeletonText, showToast } from "@calcom/ui"; | ||
|
||
import { InstallAppButtonChild } from "./InstallAppButtonChild"; | ||
import { MultiDisconnectIntegration } from "./MultiDisconnectIntegration"; | ||
|
||
export type AppPageProps = { | ||
name: string; | ||
|
@@ -98,6 +99,11 @@ export const AppPage = ({ | |
* which is caused by heavy queries in getServersideProps. This causes the loader to turn off before the page changes. | ||
*/ | ||
const [isLoading, setIsLoading] = useState<boolean>(mutation.isPending); | ||
const availableForTeams = doesAppSupportTeamInstall({ | ||
appCategories: categories, | ||
concurrentMeetings: concurrentMeetings, | ||
isPaid: !!paid, | ||
}); | ||
|
||
const handleAppInstall = () => { | ||
setIsLoading(true); | ||
|
@@ -113,13 +119,7 @@ export const AppPage = ({ | |
step: AppOnboardingSteps.EVENT_TYPES_STEP, | ||
}), | ||
}); | ||
} else if ( | ||
!doesAppSupportTeamInstall({ | ||
appCategories: categories, | ||
concurrentMeetings: concurrentMeetings, | ||
isPaid: !!paid, | ||
}) | ||
) { | ||
} else if (!availableForTeams) { | ||
mutation.mutate({ type }); | ||
} else { | ||
router.push(getAppOnboardingUrl({ slug, step: AppOnboardingSteps.ACCOUNTS_STEP })); | ||
|
@@ -132,8 +132,14 @@ export const AppPage = ({ | |
useGrouping: false, | ||
}).format(price); | ||
|
||
const [existingCredentials, setExistingCredentials] = useState<number[]>([]); | ||
const [showDisconnectIntegration, setShowDisconnectIntegration] = useState(false); | ||
const [existingCredentials, setExistingCredentials] = useState< | ||
NonNullable<typeof appDbQuery.data>["credentials"] | ||
>([]); | ||
|
||
/** | ||
* Marks whether the app is installed for all possible teams and the user. | ||
*/ | ||
const [appInstalledForAllTargets, setAppInstalledForAllTargets] = useState(false); | ||
|
||
const appDbQuery = trpc.viewer.appCredentialsByType.useQuery({ appType: type }); | ||
|
||
|
@@ -142,12 +148,15 @@ export const AppPage = ({ | |
const data = appDbQuery.data; | ||
|
||
const credentialsCount = data?.credentials.length || 0; | ||
setShowDisconnectIntegration( | ||
data?.userAdminTeams.length ? credentialsCount >= data?.userAdminTeams.length : credentialsCount > 0 | ||
); | ||
setExistingCredentials(data?.credentials.map((credential) => credential.id) || []); | ||
setExistingCredentials(data?.credentials || []); | ||
|
||
const appInstalledForAllTargets = | ||
availableForTeams && data?.userAdminTeams | ||
? credentialsCount >= data?.userAdminTeams.length | ||
: credentialsCount > 0; | ||
setAppInstalledForAllTargets(appInstalledForAllTargets); | ||
}, | ||
[appDbQuery.data] | ||
[appDbQuery.data, availableForTeams] | ||
); | ||
|
||
const dependencyData = trpc.viewer.appsRouter.queryForDependencies.useQuery(dependencies, { | ||
|
@@ -168,6 +177,89 @@ export const AppPage = ({ | |
} | ||
}, []); | ||
|
||
const installOrDisconnectAppButton = () => { | ||
if (appDbQuery.isPending) { | ||
return <SkeletonButton className="h-10 w-24" />; | ||
} | ||
|
||
const MultiInstallButtonEl = ( | ||
<InstallAppButton | ||
type={type} | ||
disableInstall={disableInstall} | ||
teamsPlanRequired={teamsPlanRequired} | ||
render={({ useDefaultComponent, ...props }) => { | ||
if (useDefaultComponent) { | ||
props = { | ||
...props, | ||
onClick: () => { | ||
handleAppInstall(); | ||
}, | ||
loading: isLoading, | ||
}; | ||
} | ||
return <InstallAppButtonChild multiInstall paid={paid} {...props} />; | ||
}} | ||
/> | ||
); | ||
|
||
const SingleInstallButtonEl = ( | ||
<InstallAppButton | ||
type={type} | ||
disableInstall={disableInstall} | ||
teamsPlanRequired={teamsPlanRequired} | ||
render={({ useDefaultComponent, ...props }) => { | ||
if (useDefaultComponent) { | ||
props = { | ||
...props, | ||
onClick: () => { | ||
handleAppInstall(); | ||
}, | ||
loading: isLoading, | ||
}; | ||
} | ||
return <InstallAppButtonChild credentials={appDbQuery.data?.credentials} paid={paid} {...props} />; | ||
}} | ||
/> | ||
); | ||
|
||
return ( | ||
<div className="flex items-center space-x-3"> | ||
{isGlobal || | ||
(existingCredentials.length > 0 && allowedMultipleInstalls ? ( | ||
<div className="flex space-x-3"> | ||
<Button StartIcon="check" color="secondary" disabled> | ||
{existingCredentials.length > 0 | ||
? t("active_install", { count: existingCredentials.length }) | ||
: t("default")} | ||
</Button> | ||
{!isGlobal && !appInstalledForAllTargets && MultiInstallButtonEl} | ||
</div> | ||
) : ( | ||
!appInstalledForAllTargets && SingleInstallButtonEl | ||
))} | ||
|
||
{existingCredentials.length > 0 && ( | ||
<> | ||
{existingCredentials.length > 1 ? ( | ||
<MultiDisconnectIntegration | ||
credentials={existingCredentials} | ||
onSuccess={() => appDbQuery.refetch()} | ||
/> | ||
) : ( | ||
<DisconnectIntegration | ||
buttonProps={{ color: "secondary" }} | ||
label={t("disconnect")} | ||
credentialId={Number(existingCredentials[0].id)} | ||
teamId={existingCredentials[0].teamId} | ||
onSuccess={() => appDbQuery.refetch()} | ||
/> | ||
Comment on lines
+243
to
+255
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. I think we could make |
||
)} | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="relative mt-4 flex-1 flex-col items-start justify-start px-4 md:mt-0 md:flex md:px-8 lg:flex-row lg:px-0"> | ||
{hasDescriptionItems && ( | ||
|
@@ -240,68 +332,7 @@ export const AppPage = ({ | |
)} | ||
</header> | ||
</div> | ||
{!appDbQuery.isPending ? ( | ||
isGlobal || | ||
(existingCredentials.length > 0 && allowedMultipleInstalls ? ( | ||
<div className="flex space-x-3"> | ||
<Button StartIcon="check" color="secondary" disabled> | ||
{existingCredentials.length > 0 | ||
? t("active_install", { count: existingCredentials.length }) | ||
: t("default")} | ||
</Button> | ||
{!isGlobal && ( | ||
<InstallAppButton | ||
type={type} | ||
disableInstall={disableInstall} | ||
teamsPlanRequired={teamsPlanRequired} | ||
render={({ useDefaultComponent, ...props }) => { | ||
if (useDefaultComponent) { | ||
props = { | ||
...props, | ||
onClick: () => { | ||
handleAppInstall(); | ||
}, | ||
loading: isLoading, | ||
}; | ||
} | ||
return <InstallAppButtonChild multiInstall paid={paid} {...props} />; | ||
}} | ||
/> | ||
)} | ||
</div> | ||
) : showDisconnectIntegration ? ( | ||
<DisconnectIntegration | ||
buttonProps={{ color: "secondary" }} | ||
label={t("disconnect")} | ||
credentialId={existingCredentials[0]} | ||
onSuccess={() => { | ||
appDbQuery.refetch(); | ||
}} | ||
/> | ||
) : ( | ||
<InstallAppButton | ||
type={type} | ||
disableInstall={disableInstall} | ||
teamsPlanRequired={teamsPlanRequired} | ||
render={({ useDefaultComponent, ...props }) => { | ||
if (useDefaultComponent) { | ||
props = { | ||
...props, | ||
onClick: () => { | ||
handleAppInstall(); | ||
}, | ||
loading: isLoading, | ||
}; | ||
} | ||
return ( | ||
<InstallAppButtonChild credentials={appDbQuery.data?.credentials} paid={paid} {...props} /> | ||
); | ||
}} | ||
/> | ||
)) | ||
) : ( | ||
<SkeletonButton className="h-10 w-24" /> | ||
)} | ||
{installOrDisconnectAppButton()} | ||
|
||
{dependencies && | ||
(!dependencyData.isPending ? ( | ||
|
109 changes: 109 additions & 0 deletions
109
apps/web/components/apps/MultiDisconnectIntegration.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,109 @@ | ||
import { useState } from "react"; | ||
|
||
import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
import { trpc } from "@calcom/trpc/react"; | ||
import type { AppRouter } from "@calcom/trpc/server/routers/_app"; | ||
import { | ||
Button, | ||
Dropdown, | ||
DropdownMenuTrigger, | ||
DropdownMenuContent, | ||
DropdownMenuLabel, | ||
DropdownMenuItem, | ||
DropdownItem, | ||
Dialog, | ||
ConfirmationDialogContent, | ||
showToast, | ||
} from "@calcom/ui"; | ||
|
||
import type { inferRouterOutputs } from "@trpc/server"; | ||
|
||
type RouterOutput = inferRouterOutputs<AppRouter>; | ||
type Credentials = RouterOutput["viewer"]["appCredentialsByType"]["credentials"]; | ||
|
||
interface Props { | ||
credentials: Credentials; | ||
onSuccess?: () => void; | ||
} | ||
|
||
export function MultiDisconnectIntegration({ credentials, onSuccess }: Props) { | ||
const { t } = useLocale(); | ||
const utils = trpc.useUtils(); | ||
const [credentialToDelete, setCredentialToDelete] = useState<{ | ||
id: number; | ||
teamId: number | null; | ||
name: string | null; | ||
} | null>(null); | ||
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false); | ||
|
||
const mutation = trpc.viewer.deleteCredential.useMutation({ | ||
onSuccess: () => { | ||
showToast(t("app_removed_successfully"), "success"); | ||
onSuccess && onSuccess(); | ||
setConfirmationDialogOpen(false); | ||
}, | ||
onError: () => { | ||
showToast(t("error_removing_app"), "error"); | ||
setConfirmationDialogOpen(false); | ||
}, | ||
async onSettled() { | ||
await utils.viewer.connectedCalendars.invalidate(); | ||
await utils.viewer.integrations.invalidate(); | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<Dropdown> | ||
<DropdownMenuTrigger asChild> | ||
<Button color="secondary">{t("disconnect")}</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuLabel> | ||
<div className="w-48 text-left text-xs">{t("disconnect_app_from")}</div> | ||
</DropdownMenuLabel> | ||
{credentials.map((cred) => ( | ||
<DropdownMenuItem key={cred.id}> | ||
<DropdownItem | ||
type="button" | ||
color="destructive" | ||
className="hover:bg-subtle hover:text-emphasis w-full border-0" | ||
StartIcon={cred.teamId ? "users" : "user"} | ||
onClick={() => { | ||
setCredentialToDelete({ | ||
id: cred.id, | ||
teamId: cred.teamId, | ||
name: cred.team?.name || cred.user?.name || null, | ||
}); | ||
setConfirmationDialogOpen(true); | ||
}}> | ||
<div className="flex flex-col text-left"> | ||
<span>{cred.team?.name || cred.user?.name || t("unnamed")}</span> | ||
</div> | ||
</DropdownItem> | ||
</DropdownMenuItem> | ||
))} | ||
</DropdownMenuContent> | ||
</Dropdown> | ||
|
||
<Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}> | ||
<ConfirmationDialogContent | ||
variety="danger" | ||
title={t("remove_app")} | ||
confirmBtnText={t("yes_remove_app")} | ||
onConfirm={() => { | ||
if (credentialToDelete) { | ||
mutation.mutate({ | ||
id: credentialToDelete.id, | ||
...(credentialToDelete.teamId ? { teamId: credentialToDelete.teamId } : {}), | ||
}); | ||
} | ||
}}> | ||
<p className="mt-5"> | ||
{t("are_you_sure_you_want_to_remove_this_app_from")} {credentialToDelete?.name || t("unnamed")}? | ||
</p> | ||
</ConfirmationDialogContent> | ||
</Dialog> | ||
</> | ||
); | ||
} |
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.
Made this logic a bit easier to understand by moving the JSX to variables above