mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: slack with project integration bug fixes
This commit is contained in:
parent
160b4a4390
commit
2dc5655886
@ -5,14 +5,13 @@ import { useRouter } from "next/router";
|
|||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
// services
|
// services
|
||||||
import appinstallationsService from "services/app-installations.service";
|
import appinstallationsService from "services/app-installations.service";
|
||||||
|
|
||||||
// ui
|
// ui
|
||||||
import { Loader } from "components/ui";
|
import { Loader } from "components/ui";
|
||||||
// hooks
|
// hooks
|
||||||
import useToast from "hooks/use-toast";
|
import useToast from "hooks/use-toast";
|
||||||
import useIntegrationPopup from "hooks/use-integration-popup";
|
import useIntegrationPopup from "hooks/use-integration-popup";
|
||||||
// types
|
// types
|
||||||
import { IWorkspaceIntegration } from "types";
|
import { IWorkspaceIntegration, ISlackIntegration } from "types";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { SLACK_CHANNEL_INFO } from "constants/fetch-keys";
|
import { SLACK_CHANNEL_INFO } from "constants/fetch-keys";
|
||||||
|
|
||||||
@ -21,7 +20,9 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SelectChannel: React.FC<Props> = ({ integration }) => {
|
export const SelectChannel: React.FC<Props> = ({ integration }) => {
|
||||||
const [deletingProjectSync, setDeletingProjectSync] = useState(false);
|
const [slackChannelAvailabilityToggle, setSlackChannelAvailabilityToggle] =
|
||||||
|
useState<boolean>(false);
|
||||||
|
const [slackChannel, setSlackChannel] = useState<ISlackIntegration | null>(null);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId } = router.query;
|
const { workspaceSlug, projectId } = router.query;
|
||||||
@ -43,33 +44,38 @@ export const SelectChannel: React.FC<Props> = ({ integration }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (projectIntegration?.length > 0) {
|
if (projectId && projectIntegration && projectIntegration.length > 0) {
|
||||||
setDeletingProjectSync(true);
|
const projectSlackIntegrationCheck: ISlackIntegration | undefined = projectIntegration.find(
|
||||||
|
(_slack: ISlackIntegration) => _slack.project === projectId
|
||||||
|
);
|
||||||
|
if (projectSlackIntegrationCheck) {
|
||||||
|
setSlackChannel(() => projectSlackIntegrationCheck);
|
||||||
|
setSlackChannelAvailabilityToggle(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (projectIntegration?.length === 0) {
|
}, [projectIntegration, projectId]);
|
||||||
setDeletingProjectSync(false);
|
|
||||||
}
|
|
||||||
}, [projectIntegration]);
|
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
if (projectIntegration.length === 0) return;
|
if (projectIntegration.length === 0) return;
|
||||||
mutate(SLACK_CHANNEL_INFO, (prevData: any) => {
|
mutate(SLACK_CHANNEL_INFO, (prevData: any) => {
|
||||||
if (!prevData) return;
|
if (!prevData) return;
|
||||||
return prevData.id !== integration.id;
|
return prevData.id !== integration.id;
|
||||||
}).then(() => setDeletingProjectSync(false));
|
}).then(() => {
|
||||||
|
setSlackChannelAvailabilityToggle(false);
|
||||||
|
setSlackChannel(null);
|
||||||
|
});
|
||||||
appinstallationsService
|
appinstallationsService
|
||||||
.removeSlackChannel(
|
.removeSlackChannel(
|
||||||
workspaceSlug as string,
|
workspaceSlug as string,
|
||||||
projectId as string,
|
projectId as string,
|
||||||
integration.id as string,
|
integration.id as string,
|
||||||
projectIntegration?.[0]?.id
|
slackChannel?.id
|
||||||
)
|
)
|
||||||
.catch((err) => console.log(err));
|
.catch((err) => console.log(err));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAuth = async () => {
|
const handleAuth = async () => {
|
||||||
await startAuth();
|
await startAuth();
|
||||||
setDeletingProjectSync(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -78,20 +84,18 @@ export const SelectChannel: React.FC<Props> = ({ integration }) => {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
className={`relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
||||||
projectIntegration.length > 0 && deletingProjectSync ? "bg-green-500" : "bg-gray-200"
|
slackChannelAvailabilityToggle ? "bg-green-500" : "bg-gray-200"
|
||||||
}`}
|
}`}
|
||||||
role="switch"
|
role="switch"
|
||||||
aria-checked
|
aria-checked
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
deletingProjectSync ? handleDelete() : handleAuth();
|
slackChannelAvailabilityToggle ? handleDelete() : handleAuth();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className={`inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${
|
className={`inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${
|
||||||
projectIntegration.length > 0 && deletingProjectSync
|
slackChannelAvailabilityToggle ? "translate-x-5" : "translate-x-0"
|
||||||
? "translate-x-5"
|
|
||||||
: "translate-x-0"
|
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
41
apps/app/types/integration.d.ts
vendored
41
apps/app/types/integration.d.ts
vendored
@ -33,3 +33,44 @@ export interface IWorkspaceIntegration {
|
|||||||
updated_by: string;
|
updated_by: string;
|
||||||
workspace: string;
|
workspace: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// slack integration
|
||||||
|
export interface ISlackIntegration {
|
||||||
|
id: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
access_token: string;
|
||||||
|
scopes: string;
|
||||||
|
bot_user_id: string;
|
||||||
|
webhook_url: string;
|
||||||
|
data: ISlackIntegrationData;
|
||||||
|
team_id: string;
|
||||||
|
team_name: string;
|
||||||
|
created_by: string;
|
||||||
|
updated_by: string;
|
||||||
|
project: string;
|
||||||
|
workspace: string;
|
||||||
|
workspace_integration: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISlackIntegrationData {
|
||||||
|
ok: boolean;
|
||||||
|
team: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
scope: string;
|
||||||
|
app_id: string;
|
||||||
|
enterprise: any;
|
||||||
|
token_type: string;
|
||||||
|
authed_user: string;
|
||||||
|
bot_user_id: string;
|
||||||
|
access_token: string;
|
||||||
|
incoming_webhook: {
|
||||||
|
url: string;
|
||||||
|
channel: string;
|
||||||
|
channel_id: string;
|
||||||
|
configuration_url: string;
|
||||||
|
};
|
||||||
|
is_enterprise_install: boolean;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user