Skip to content

Commit

Permalink
[calendar] Fix calendar sync status (twentyhq#5272)
Browse files Browse the repository at this point in the history
## Context
There is no calendarChannel syncStatus column compared to the
messageChannel table. In the meantime, we are trying to infer its status
based on the fact that the connection hasn't failed and the sync is
enabled
  • Loading branch information
Weiko committed May 3, 2024
1 parent 87994c2 commit 2a0c74a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { IconChevronRight, IconGoogleCalendar } from 'twenty-ui';
import { CalendarChannel } from '@/accounts/types/CalendarChannel';
import { ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { SettingsAccountsListEmptyStateCard } from '@/settings/accounts/components/SettingsAccountsListEmptyStateCard';
import {
Expand All @@ -25,6 +27,9 @@ const StyledRowRightContainer = styled.div`
export const SettingsAccountsCalendarChannelsListCard = () => {
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const navigate = useNavigate();
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular: CoreObjectNameSingular.CalendarChannel,
});

const { records: accounts, loading: accountsLoading } =
useFindManyRecords<ConnectedAccount>({
Expand All @@ -49,6 +54,7 @@ export const SettingsAccountsCalendarChannelsListCard = () => {
in: accounts.map((account) => account.id),
},
},
recordGqlFields: generateDepthOneRecordGqlFields({ objectMetadataItem }),
});

if (!calendarChannels.length) {
Expand All @@ -61,10 +67,8 @@ export const SettingsAccountsCalendarChannelsListCard = () => {
(calendarChannel) => ({
...calendarChannel,
syncStatus: calendarChannel.connectedAccount?.authFailedAt
? 'failed'
: calendarChannel.isSyncEnabled
? 'synced'
: 'notSynced',
? 'FAILED'
: 'SUCCEEDED',
}),
);

Expand All @@ -81,6 +85,7 @@ export const SettingsAccountsCalendarChannelsListCard = () => {
<StyledRowRightContainer>
<SettingsAccountsSynchronizationStatus
syncStatus={calendarChannel.syncStatus}
isSyncEnabled={calendarChannel.isSyncEnabled}
/>
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRowRightContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const SettingsAccountsMessageChannelsListCard = () => {
<StyledRowRightContainer>
<SettingsAccountsSynchronizationStatus
syncStatus={messageChannel.syncStatus}
isSyncEnabled={messageChannel.isSyncEnabled}
/>
<LightIconButton Icon={IconChevronRight} accent="tertiary" />
</StyledRowRightContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import { Status } from '@/ui/display/status/components/Status';

export type SettingsAccountsSynchronizationStatusProps = {
syncStatus: string;
isSyncEnabled?: boolean;
};

export const SettingsAccountsSynchronizationStatus = ({
syncStatus,
isSyncEnabled,
}: SettingsAccountsSynchronizationStatusProps) => {
const syncStatusOptions = useGetSyncStatusOptions();

const syncStatusOption = syncStatusOptions?.find(
(option) => option.value === syncStatus,
);

if (!isSyncEnabled) {
return <Status color="gray" text="Not synced" weight="medium" />;
}

return (
<Status
color={syncStatusOption?.color ?? 'gray'}
Expand Down

0 comments on commit 2a0c74a

Please sign in to comment.