-
Notifications
You must be signed in to change notification settings - Fork 5k
Added option to prevent sending requests to twenty-icons #16723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
1d25808
d0a89c1
12ae5f7
88fbb41
a44f936
4f54c46
29fb658
d783c5e
4aa1caf
788eb9f
1806c68
9123cf8
28051a9
5ad9f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ import { | |
| getLogoUrlFromDomainName, | ||
| isDefined, | ||
| } from 'twenty-shared/utils'; | ||
| import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; | ||
| import { useRecoilState } from 'recoil'; | ||
|
|
||
| export const getAvatarUrl = ( | ||
| objectNameSingular: string, | ||
|
|
@@ -20,7 +22,13 @@ export const getAvatarUrl = ( | |
| return record.avatarUrl ?? undefined; | ||
| } | ||
|
|
||
| if (objectNameSingular === CoreObjectNameSingular.Company) { | ||
| // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| const [currentWorkspace] = useRecoilState(currentWorkspaceState); | ||
|
||
|
|
||
| if ( | ||
| objectNameSingular === CoreObjectNameSingular.Company && | ||
| currentWorkspace?.allowRequests === true | ||
| ) { | ||
| return getLogoUrlFromDomainName( | ||
| getCompanyDomainName(record as Company) ?? '', | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { useRecoilState } from 'recoil'; | ||
|
|
||
| import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; | ||
| import { SettingsOptionCardContentToggle } from '@/settings/components/SettingsOptions/SettingsOptionCardContentToggle'; | ||
| import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
| import { ApolloError } from '@apollo/client'; | ||
| import { t } from '@lingui/core/macro'; | ||
| import { Card } from 'twenty-ui/layout'; | ||
| import { useUpdateWorkspaceMutation } from '~/generated-metadata/graphql'; | ||
| import { IconHttpGet, IconTrash } from 'twenty-ui/display'; | ||
| import styled from '@emotion/styled'; | ||
| import { SettingsOptionCardContentCounter } from '@/settings/components/SettingsOptions/SettingsOptionCardContentCounter'; | ||
| import { useDebouncedCallback } from 'use-debounce'; | ||
|
|
||
| export const SettingsSecurityOther = () => { | ||
| const StyledToggleRequests = styled.div` | ||
|
||
| display: flex; | ||
| flex-direction: column; | ||
| gap: ${({ theme }) => theme.spacing(4)}; | ||
| `; | ||
|
|
||
BOHEUS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const { enqueueErrorSnackBar } = useSnackBar(); | ||
|
|
||
| const [currentWorkspace, setCurrentWorkspace] = useRecoilState( | ||
| currentWorkspaceState, | ||
| ); | ||
|
|
||
| const [updateWorkspace] = useUpdateWorkspaceMutation(); | ||
|
|
||
| const saveWorkspace = useDebouncedCallback(async (value: number) => { | ||
| try { | ||
| if (!currentWorkspace?.id) { | ||
| throw new Error('User is not logged in'); | ||
| } | ||
|
|
||
| await updateWorkspace({ | ||
| variables: { | ||
| input: { | ||
| trashRetentionDays: value, | ||
| }, | ||
| }, | ||
| }); | ||
| } catch (err) { | ||
| enqueueErrorSnackBar({ | ||
| apolloError: err instanceof ApolloError ? err : undefined, | ||
| }); | ||
| } | ||
| }, 500); | ||
|
|
||
| const handleTrashRetentionDaysChange = (value: number) => { | ||
| if (!currentWorkspace) { | ||
| return; | ||
| } | ||
|
|
||
| if (value === currentWorkspace.trashRetentionDays) { | ||
| return; | ||
| } | ||
|
|
||
| setCurrentWorkspace({ | ||
| ...currentWorkspace, | ||
| trashRetentionDays: value, | ||
| }); | ||
|
|
||
| saveWorkspace(value); | ||
| }; | ||
|
|
||
| const handleRequestsChange = async (value: boolean) => { | ||
| try { | ||
| if (!currentWorkspace?.id) { | ||
| throw new Error('User is not logged in'); | ||
| } | ||
| await updateWorkspace({ | ||
| variables: { | ||
| input: { | ||
| allowRequests: value, | ||
| }, | ||
| }, | ||
| }); | ||
| setCurrentWorkspace({ | ||
| ...currentWorkspace, | ||
| allowRequests: value, | ||
| }); | ||
| } catch (err: any) { | ||
| enqueueErrorSnackBar({ | ||
| apolloError: err instanceof ApolloError ? err : undefined, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <StyledToggleRequests> | ||
| <Card rounded> | ||
| <SettingsOptionCardContentCounter | ||
| Icon={IconTrash} | ||
| title={t`Erasure of soft-deleted records`} | ||
| description={t`Permanent deletion. Enter the number of days.`} | ||
| value={currentWorkspace?.trashRetentionDays ?? 14} | ||
| onChange={handleTrashRetentionDaysChange} | ||
| minValue={0} | ||
| showButtons={false} | ||
| /> | ||
| </Card> | ||
| <Card rounded> | ||
| <SettingsOptionCardContentToggle | ||
| Icon={IconHttpGet} | ||
| title={t`Allow requests to twenty-icons`} | ||
| description={t`Grant access to send requests to twenty-icons to show companies' icons.`} | ||
| checked={currentWorkspace?.allowRequests ?? false} | ||
| onChange={handleRequestsChange} | ||
| advancedMode | ||
| /> | ||
| </Card> | ||
| </StyledToggleRequests> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { type MigrationInterface, type QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AllowRequests1766176556359 implements MigrationInterface { | ||
| name = 'AllowRequests1766176556359'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "core"."workspace" ADD "allowRequests" boolean NOT NULL DEFAULT true`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "core"."workspace" DROP COLUMN "allowRequests"`, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An eslint-disable comment is being used to suppress the React Hooks rules violation, but this doesn't fix the underlying issue. The code will still fail at runtime because React Hooks cannot be called from regular functions. This suppression should be removed, and the code should be properly refactored to pass the workspace state as a parameter instead of calling the hook.