fix: Attach `credentialId` to location option (#12086)

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit222001@gmail.com>
This commit is contained in:
Joe Au-Yeung 2023-11-01 09:34:05 -04:00 committed by GitHub
parent 51fd4102ae
commit 3bb42f276e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 9 deletions

View File

@ -356,9 +356,9 @@ export const EditLocationDialog = (props: ISetLocationDialog) => {
onChange={(val) => { onChange={(val) => {
if (val) { if (val) {
locationFormMethods.setValue("locationType", val.value); locationFormMethods.setValue("locationType", val.value);
if (val.credential) { if (!!val.credentialId) {
locationFormMethods.setValue("credentialId", val.credential.id); locationFormMethods.setValue("credentialId", val.credentialId);
locationFormMethods.setValue("teamName", val.credential.team?.name); locationFormMethods.setValue("teamName", val.teamName);
} }
locationFormMethods.unregister([ locationFormMethods.unregister([

View File

@ -298,9 +298,21 @@ export const EventSetupTab = (
!validLocations.find((location) => location.type === newLocationType); !validLocations.find((location) => location.type === newLocationType);
if (canAddLocation) { if (canAddLocation) {
updateLocationField(index, { type: newLocationType }); updateLocationField(index, {
type: newLocationType,
...(e.credentialId && {
credentialId: e.credentialId,
teamName: e.teamName,
}),
});
} else { } else {
updateLocationField(index, { type: field.type }); updateLocationField(index, {
type: field.type,
...(field.credentialId && {
credentialId: field.credentialId,
teamName: field.teamName,
}),
});
showToast(t("location_already_exists"), "warning"); showToast(t("location_already_exists"), "warning");
} }
} }
@ -382,7 +394,13 @@ export const EventSetupTab = (
!validLocations.find((location) => location.type === newLocationType); !validLocations.find((location) => location.type === newLocationType);
if (canAppendLocation) { if (canAppendLocation) {
append({ type: newLocationType }); append({
type: newLocationType,
...(e.credentialId && {
credentialId: e.credentialId,
teamName: e.teamName,
}),
});
setSelectedNewOption(e); setSelectedNewOption(e);
} else { } else {
showToast(t("location_already_exists"), "warning"); showToast(t("location_already_exists"), "warning");

View File

@ -2,7 +2,6 @@ import type { GroupBase, Props, SingleValue } from "react-select";
import { components } from "react-select"; import { components } from "react-select";
import type { EventLocationType } from "@calcom/app-store/locations"; import type { EventLocationType } from "@calcom/app-store/locations";
import type { CredentialDataWithTeamName } from "@calcom/app-store/utils";
import { classNames } from "@calcom/lib"; import { classNames } from "@calcom/lib";
import invertLogoOnDark from "@calcom/lib/invertLogoOnDark"; import invertLogoOnDark from "@calcom/lib/invertLogoOnDark";
import { Select } from "@calcom/ui"; import { Select } from "@calcom/ui";
@ -13,7 +12,8 @@ export type LocationOption = {
icon?: string; icon?: string;
disabled?: boolean; disabled?: boolean;
address?: string; address?: string;
credential?: CredentialDataWithTeamName; credentialId?: number;
teamName?: string;
}; };
export type SingleValueLocationOption = SingleValue<LocationOption>; export type SingleValueLocationOption = SingleValue<LocationOption>;

View File

@ -88,7 +88,13 @@ export async function getLocationGroupedOptions(
teamName: credential.team?.name, teamName: credential.team?.name,
}))) { }))) {
const label = `${app.locationOption.label} ${teamName ? `(${teamName})` : ""}`; const label = `${app.locationOption.label} ${teamName ? `(${teamName})` : ""}`;
const option = { ...app.locationOption, label, icon: app.logo, slug: app.slug }; const option = {
...app.locationOption,
label,
icon: app.logo,
slug: app.slug,
...(app.credential ? { credentialId: app.credential.id, teamName: app.credential.team?.name } : {}),
};
if (apps[groupByCategory]) { if (apps[groupByCategory]) {
apps[groupByCategory] = [...apps[groupByCategory], option]; apps[groupByCategory] = [...apps[groupByCategory], option];
} else { } else {