Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions web-server/pages/api/resources/orgs/[org_id]/teams/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ endpoint.handle.GET(getSchema, async (req, res) => {

const [teams, orgRepos] = await Promise.all([
getQuery,
(
await getAllOrgRepos(org_id, provider as CodeSourceProvidersIntegration)
).flat()
getAllOrgRepos(org_id, provider as CodeSourceProvidersIntegration).then(
(res) => res.flat()
)
]);

const repos = (
await Promise.all(teams.map((team) => getTeamRepos(team.id)))
).flat();
Expand Down
48 changes: 25 additions & 23 deletions web-server/src/components/Teams/useTeamsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const TeamsCRUDProvider: React.FC<{
const teamReposMaps = useSelector((s) => s.team.teamReposMaps);
const teams = useSelector((s) => s.team.teams);
const orgRepos = useSelector((s) => s.team.orgRepos);
const { orgId, org } = useAuth();
const { orgId } = useAuth();
const isPageLoading = useSelector(
(s) => s.team.requests?.teams === FetchState.REQUEST
);
Expand Down Expand Up @@ -180,16 +180,8 @@ export const TeamsCRUDProvider: React.FC<{
const teamCreation = useCallback(
async (callBack?: AnyFunction) => {
depFn(isSaveLoading.true);
const repoPayload = {
[org?.name]: selections.value.map(
(repo) =>
({
idempotency_key: repo.id,
name: repo.name,
slug: repo.slug
}) as RepoUniqueDetails
)
};
const repoPayload = repoToPayload(selections.value);

return dispatch(
createTeam({
org_id: orgId,
Expand Down Expand Up @@ -221,7 +213,6 @@ export const TeamsCRUDProvider: React.FC<{
fetchTeamsAndRepos,
isSaveLoading.false,
isSaveLoading.true,
org?.name,
orgId,
selections.value,
teamName.value
Expand All @@ -231,16 +222,8 @@ export const TeamsCRUDProvider: React.FC<{
const teamUpdation = useCallback(
async (callBack?: AnyFunction) => {
depFn(isSaveLoading.true);
const repoPayload = {
[org?.name]: selections.value.map(
(repo) =>
({
idempotency_key: repo.id,
name: repo.name,
slug: repo.slug
}) as RepoUniqueDetails
)
};
const repoPayload = repoToPayload(selections.value);

return dispatch(
updateTeam({
team_id: teamId,
Expand Down Expand Up @@ -273,7 +256,6 @@ export const TeamsCRUDProvider: React.FC<{
fetchTeamsAndRepos,
isSaveLoading.false,
isSaveLoading.true,
org?.name,
orgId,
selections.value,
teamId,
Expand Down Expand Up @@ -367,3 +349,23 @@ export const TeamsCRUDProvider: React.FC<{
</TeamsCRUDContext.Provider>
);
};

const repoToPayload = (repos: BaseRepo[]) => {
const repoPayload = {} as Record<string, RepoUniqueDetails[]>;
repos.forEach((repo) => {
const orgRepo = {
idempotency_key: repo.id,
name: repo.name,
slug: repo.slug
} as RepoUniqueDetails;
const orgName = repo.parent;

if (repoPayload[orgName]) {
repoPayload[orgName].push(orgRepo);
} else {
repoPayload[orgName] = [orgRepo];
}
});

return repoPayload;
};
37 changes: 21 additions & 16 deletions web-server/src/content/Dashboards/IntegrationCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,27 @@ export const GithubIntegrationCard = () => {
link.github();
return;
}
localLoading.true();
await unlink
.github()
.then(() => {
enqueueSnackbar('Github unlinked successfully', {
variant: 'success'
});
})
.then(async () => dispatch(fetchCurrentOrg()))
.catch((e) => {
console.error('Failed to unlink Github', e);
enqueueSnackbar('Failed to unlink Github', {
variant: 'error'
});
})
.finally(localLoading.false);
const shouldExecute = window.confirm(
'Are you sure you want to unlink?'
);
if (shouldExecute) {
localLoading.true();
await unlink
.github()
.then(() => {
enqueueSnackbar('Github unlinked successfully', {
variant: 'success'
});
})
.then(async () => dispatch(fetchCurrentOrg()))
.catch((e) => {
console.error('Failed to unlink Github', e);
enqueueSnackbar('Failed to unlink Github', {
variant: 'error'
});
})
.finally(localLoading.false);
}
}}
label={!isLinked ? 'Link' : 'Unlink'}
bgOpacity={!isLinked ? 0.45 : 0.25}
Expand Down