bddd23fd9c
fixes application chip (icon Name) in all setting tables ## After <img width="1200" height="896" alt="image" src="https://github.com/user-attachments/assets/bd377f47-1d52-4142-b904-f2ce90c1db78" /> <img width="1200" height="917" alt="image" src="https://github.com/user-attachments/assets/f49cc742-f11e-47e3-86ed-34beffe493c7" /> <img width="1234" height="878" alt="image" src="https://github.com/user-attachments/assets/2ab459de-5f9d-4d39-9490-eec4ed9ee432" /> <img width="1239" height="845" alt="image" src="https://github.com/user-attachments/assets/3c1bf258-285a-47b9-a60d-05ba1564334d" /> <img width="1183" height="907" alt="image" src="https://github.com/user-attachments/assets/715b2470-2d88-48e3-88ac-d3daf3451717" /> <img width="1300" height="912" alt="image" src="https://github.com/user-attachments/assets/d7c829fa-bf1d-4f19-82de-a8bf29e22bfa" />
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import {
|
|
type ApplicationAvatarColors,
|
|
useApplicationAvatarColors,
|
|
} from '@/applications/hooks/useApplicationAvatarColors';
|
|
import { isTwentyStandardApplication } from '@/applications/utils/isTwentyStandardApplication';
|
|
import { isWorkspaceCustomApplication } from '@/applications/utils/isWorkspaceCustomApplication';
|
|
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
import { t } from '@lingui/core/macro';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { buildApplicationLogoUrl } from '@/applications/utils/buildApplicationLogoUrl';
|
|
import CustomLogo from '~/pages/settings/applications/assets/custom-illustrations/custom-logo.webp';
|
|
import StandardLogo from '~/pages/settings/applications/assets/standard-illustrations/standard-logo.webp';
|
|
|
|
type UseApplicationChipDataArgs = {
|
|
applicationId?: string | null;
|
|
fallbackApplicationData?: {
|
|
logo?: string | null;
|
|
name?: string | null;
|
|
};
|
|
};
|
|
|
|
type ApplicationChipData = {
|
|
name: string;
|
|
seed: string;
|
|
colors?: ApplicationAvatarColors;
|
|
logo?: string;
|
|
};
|
|
|
|
type UseApplicationChipDataReturnType = {
|
|
applicationChipData: ApplicationChipData;
|
|
};
|
|
|
|
export const useApplicationChipData = ({
|
|
applicationId,
|
|
fallbackApplicationData,
|
|
}: UseApplicationChipDataArgs): UseApplicationChipDataReturnType => {
|
|
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
|
|
|
|
const application = currentWorkspace?.installedApplications.find(
|
|
(installedApplication) => installedApplication.id === applicationId,
|
|
);
|
|
|
|
const colors = useApplicationAvatarColors(application);
|
|
|
|
if (!isDefined(application)) {
|
|
return {
|
|
applicationChipData: {
|
|
name: fallbackApplicationData?.name ?? '',
|
|
logo: fallbackApplicationData?.logo ?? '',
|
|
seed: fallbackApplicationData?.name ?? '',
|
|
},
|
|
};
|
|
}
|
|
|
|
const isStandard = isTwentyStandardApplication(application);
|
|
|
|
const isCustom = isWorkspaceCustomApplication(application, currentWorkspace);
|
|
|
|
const displayName = isStandard
|
|
? t`Standard`
|
|
: isCustom
|
|
? t`Custom`
|
|
: application.name;
|
|
|
|
const logo = isStandard
|
|
? new URL(StandardLogo, window.location.href).toString()
|
|
: isCustom
|
|
? new URL(CustomLogo, window.location.href).toString()
|
|
: buildApplicationLogoUrl({
|
|
applicationId: application.id,
|
|
logo: application.logo,
|
|
workspaceId: currentWorkspace?.id,
|
|
});
|
|
|
|
return {
|
|
applicationChipData: {
|
|
name: displayName,
|
|
seed: application.name,
|
|
colors,
|
|
logo,
|
|
},
|
|
};
|
|
};
|