Files
twenty/packages/twenty-front/src/modules/ai/components/internal/AgentChatFileUploadButton.tsx
T
Charles Bochet d7f025157b Migrate more to Jotai (#17968)
As per title

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
2026-02-17 19:24:36 +01:00

60 lines
1.6 KiB
TypeScript

import { useAIChatFileUpload } from '@/ai/hooks/useAIChatFileUpload';
import { agentChatSelectedFilesStateV2 } from '@/ai/states/agentChatSelectedFilesStateV2';
import { useSetRecoilStateV2 } from '@/ui/utilities/state/jotai/hooks/useSetRecoilStateV2';
import styled from '@emotion/styled';
import { t } from '@lingui/core/macro';
import React, { useRef } from 'react';
import { IconPlus } from 'twenty-ui/display';
import { IconButton } from 'twenty-ui/input';
const StyledFileUploadContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(2)};
`;
const StyledFileInput = styled.input`
display: none;
`;
export const AgentChatFileUploadButton = () => {
const setAgentChatSelectedFiles = useSetRecoilStateV2(
agentChatSelectedFilesStateV2,
);
const fileInputRef = useRef<HTMLInputElement>(null);
const { uploadFiles } = useAIChatFileUpload();
const handleFileInputChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
if (!event.target.files) {
return;
}
uploadFiles(Array.from(event.target.files));
setAgentChatSelectedFiles(Array.from(event.target.files));
};
return (
<StyledFileUploadContainer>
<StyledFileInput
ref={fileInputRef}
type="file"
multiple
accept="*/*"
onChange={handleFileInputChange}
/>
<IconButton
variant="tertiary"
size="small"
onClick={() => {
fileInputRef.current?.click();
}}
Icon={IconPlus}
ariaLabel={t`Attach files`}
/>
</StyledFileUploadContainer>
);
};