* mv * wip * wip * wip * wip * plural * fix: resolve TypeScript type errors for attribute refactoring - Add TransformedAttributeOption type to handle transformed contains field - Update imports to use routing-forms Attribute type where needed - Fix getValueOfAttributeOption to use TransformedAttributeOption type - Update AttributeOptionValueWithType to use TransformedAttributeOption - Fix pre-existing lint warnings (any -> unknown, proper type casting) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * cleanup * cleanup * fix * fix * fix * fix * fix * fix: add explicit type annotation to reduce callback in getAttributes.ts Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: use RouterOutputs from @calcom/trpc/react for consistent type inference - Update AppPage.tsx to use RouterOutputs from @calcom/trpc/react instead of inferRouterOutputs<AppRouter> - Update MultiDisconnectIntegration.tsx to use the same RouterOutputs type source - Add eslint-disable comments for pre-existing warnings (useEffect deps, img elements) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: explicitly type attribute property in AttributeOptionAssignment The attribute property from Pick<AttributeOption, 'attribute'> was typed as 'unknown' because Prisma relations don't have explicit types when picked. This explicitly defines the attribute shape with id, type, and isLocked properties that are used in assignValueToUser.ts. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: remove unused assignedUsers from AttributeOptionAssignment Pick The assignedUsers property was not being used in the code but was required by the Pick type, causing a type mismatch when the actual data from the database query didn't include it. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update import path for AttributeOptionAssignment and BulkAttributeAssigner types The types.d.ts file was moved from packages/lib/service/attribute/ to packages/app-store/routing-forms/types/. Updated the import path in utils.ts to point to the new location. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
/**
|
|
* Utility functions for attribute service. Shared across server and client.
|
|
*/
|
|
import type {
|
|
AttributeOptionAssignment,
|
|
BulkAttributeAssigner,
|
|
} from "@calcom/app-store/routing-forms/types/types";
|
|
import slugify from "@calcom/lib/slugify";
|
|
import { AttributeType } from "@calcom/prisma/enums";
|
|
|
|
/**
|
|
* What is a pool?
|
|
* There can be two pools:
|
|
* 1. SCIM Pool - All assignments in this pool are created/updated by SCIM.
|
|
* 2. Cal.com User Pool - All assignments in this pool are created/updated by Cal.com Users.
|
|
*/
|
|
export const isAssignmentForTheSamePool = ({
|
|
assignment,
|
|
updater,
|
|
}: {
|
|
assignment: Pick<
|
|
AttributeOptionAssignment,
|
|
"createdByDSyncId" | "updatedByDSyncId" | "createdById" | "updatedById"
|
|
>;
|
|
updater: BulkAttributeAssigner;
|
|
}) => {
|
|
if ("dsyncId" in updater) {
|
|
// Cal.com user updated an assignment created by SCIM. It no longer belongs to the SCIM pool.
|
|
if (assignment.updatedById) {
|
|
return false;
|
|
}
|
|
// Either SCIM created the assignment or updated it
|
|
return !!assignment.updatedByDSyncId || !!assignment.createdByDSyncId;
|
|
}
|
|
// SCIM neither created nor updated the assignment, it has to belong to the only left pool(i.e. Cal.com User Pool)
|
|
return !assignment.createdByDSyncId && !assignment.updatedByDSyncId;
|
|
};
|
|
|
|
export const isAssignmentForLockedAttribute = ({
|
|
assignment,
|
|
}: {
|
|
assignment: {
|
|
attributeOption: {
|
|
attribute: {
|
|
isLocked: boolean;
|
|
};
|
|
};
|
|
};
|
|
}) => {
|
|
return assignment.attributeOption.attribute.isLocked;
|
|
};
|
|
|
|
export const isAssignmentSame = ({
|
|
existingAssignment,
|
|
newOption,
|
|
}: {
|
|
existingAssignment: { attributeOption: { label: string } };
|
|
newOption: { label: string };
|
|
}) => {
|
|
return existingAssignment.attributeOption.label.toLowerCase() === newOption.label.toLowerCase();
|
|
};
|
|
|
|
export const doesSupportMultipleValues = ({ attribute }: { attribute: { type: AttributeType } }) => {
|
|
return attribute.type === AttributeType.MULTI_SELECT;
|
|
};
|
|
|
|
export const buildSlugFromValue = ({ value }: { value: string }) => {
|
|
return slugify(value);
|
|
};
|
|
|
|
export const hasOptions = ({
|
|
attribute,
|
|
}: {
|
|
attribute: {
|
|
type: AttributeType;
|
|
};
|
|
}) => {
|
|
return attribute.type === AttributeType.MULTI_SELECT || attribute.type === AttributeType.SINGLE_SELECT;
|
|
};
|
|
|
|
export const canSetValueBeyondOptions = ({
|
|
attribute,
|
|
}: {
|
|
attribute: {
|
|
type: AttributeType;
|
|
};
|
|
}) => {
|
|
return !hasOptions({ attribute });
|
|
};
|