From 62777981e403c394abfc5951b8787eabd7cf1edf Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Thu, 5 Sep 2024 12:36:10 +0200 Subject: [PATCH] feat: wip --- .gitignore | 2 ++ apps/web/src/actions/datasets/create.ts | 8 ++++---- apps/web/src/app/(private)/datasets/new/page.tsx | 8 ++++---- apps/web/src/hooks/useLatitudeAction.ts | 2 -- apps/web/src/lib/disk.ts | 2 +- packages/core/src/lib/disk.ts | 5 ++--- packages/core/src/services/datasets/create.ts | 2 +- packages/env/src/index.ts | 6 ++---- packages/web-ui/src/ds/atoms/DropzoneInput/index.tsx | 1 - packages/web-ui/src/ds/atoms/Input/index.tsx | 1 + 10 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 2c9817b77..3669ff42e 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ docker/pgdata/ # Next.js next-env.d.ts + +apps/web/public/uploads diff --git a/apps/web/src/actions/datasets/create.ts b/apps/web/src/actions/datasets/create.ts index 5094286e2..71d918204 100644 --- a/apps/web/src/actions/datasets/create.ts +++ b/apps/web/src/actions/datasets/create.ts @@ -4,7 +4,7 @@ import { createDataset } from '@latitude-data/core/services/datasets/create' import disk from '$/lib/disk' import { z } from 'zod' -import { withProject } from '../procedures' +import { authProcedure } from '../procedures' const ACCEPTED_FILE_TYPES = [ 'text/csv', @@ -15,12 +15,12 @@ const ACCEPTED_FILE_TYPES = [ const MAX_SIZE = 3 const MAX_UPLOAD_SIZE_IN_MB = 3 * 1024 * 1024 -export const createDatasetAction = withProject +export const createDatasetAction = authProcedure .createServerAction() .input( z.object({ name: z.string().min(1, { message: 'Name is required' }), - file: z + dataset_file: z .instanceof(File) .refine((file) => { return !file || file.size <= MAX_UPLOAD_SIZE_IN_MB @@ -38,7 +38,7 @@ export const createDatasetAction = withProject disk: disk, data: { name: input.name, - file: input.file, + file: input.dataset_file, }, }) diff --git a/apps/web/src/app/(private)/datasets/new/page.tsx b/apps/web/src/app/(private)/datasets/new/page.tsx index 0bc1cf81b..29829ce07 100644 --- a/apps/web/src/app/(private)/datasets/new/page.tsx +++ b/apps/web/src/app/(private)/datasets/new/page.tsx @@ -14,12 +14,11 @@ import useLatitudeAction from '$/hooks/useLatitudeAction' import { useNavigate } from '$/hooks/useNavigate' import { ROUTES } from '$/services/routes' -// import useProjects from '$/stores/projects' - export default function NewDataset() { const data = { name: '' } const navigate = useNavigate() - const { executeFormAction } = useLatitudeAction(createDatasetAction) + const { error, executeFormAction } = useLatitudeAction(createDatasetAction) + const errors = error?.fieldErrors return ( ) => { - console.error(error) - if (error?.err?.code === 'INPUT_PARSE_ERROR') return toast({ diff --git a/apps/web/src/lib/disk.ts b/apps/web/src/lib/disk.ts index b7206692e..c8fbbce72 100644 --- a/apps/web/src/lib/disk.ts +++ b/apps/web/src/lib/disk.ts @@ -9,6 +9,6 @@ const DIRNAME_PATH = path.dirname(fileURLToPath(import.meta.url)) export default new DiskWrapper({ local: { publicPath: PUBLIC_PATH, - location: path.join(DIRNAME_PATH, `../../apps/web/public/${PUBLIC_PATH}`), + location: path.join(DIRNAME_PATH, `../../public/${PUBLIC_PATH}`), }, }) diff --git a/packages/core/src/lib/disk.ts b/packages/core/src/lib/disk.ts index 68411645a..119992cc7 100644 --- a/packages/core/src/lib/disk.ts +++ b/packages/core/src/lib/disk.ts @@ -7,9 +7,8 @@ import { FSDriver } from 'flydrive/drivers/fs' import { S3Driver } from 'flydrive/drivers/s3' import { WriteOptions } from 'flydrive/types' -const generateUrl = (publicPath: string) => async (key: string) => { - ;`/${publicPath}/${key}` -} +const generateUrl = (publicPath: string) => async (key: string) => + `/${publicPath}/${key}` function getAwsCredentials() { const accessKeyId = env.AWS_ACCESS_KEY diff --git a/packages/core/src/services/datasets/create.ts b/packages/core/src/services/datasets/create.ts index b6c7689ae..1cd752aee 100644 --- a/packages/core/src/services/datasets/create.ts +++ b/packages/core/src/services/datasets/create.ts @@ -31,7 +31,7 @@ export const createDataset = async ( const name = slugify(data.name) const extension = path.extname(data.file.name) - const fileName = `workspaces/${workspace.id}/datasets/${name}.${extension}` + const fileName = `workspaces/${workspace.id}/datasets/${name}${extension}` const diskResult = await disk.putFile(fileName, data.file) diff --git a/packages/env/src/index.ts b/packages/env/src/index.ts index a89a0cf20..7501be946 100644 --- a/packages/env/src/index.ts +++ b/packages/env/src/index.ts @@ -33,7 +33,6 @@ if (environment !== 'production') { dotenv.config({ path: pathToEnv }) } -export const DriveDiskSchema = z.union([z.literal('local'), z.literal('s3')]) export const env = createEnv({ skipValidation: process.env.BUILDING_CONTAINER == 'true' || process.env.NODE_ENV === 'test', @@ -45,13 +44,12 @@ export const env = createEnv({ REDIS_PASSWORD: z.string().optional(), LATITUDE_URL: z.string().url(), MAILER_API_KEY: z.string().optional(), - FROM_MAILER_EMAIL: z.string(), - LATITUDE_DOMAIN: z.string(), + FROM_MAILER_EMAIL: z.string(), LATITUDE_DOMAIN: z.string(), AWS_REGION: z.string().optional(), S3_BUCKET: z.string().optional(), AWS_ACCESS_KEY: z.string().optional(), AWS_ACCESS_SECRET: z.string().optional(), - DRIVE_DISK: DriveDiskSchema, + DRIVE_DISK: z.union([z.literal('local'), z.literal('s3')]) }, runtimeEnv: process.env, }) diff --git a/packages/web-ui/src/ds/atoms/DropzoneInput/index.tsx b/packages/web-ui/src/ds/atoms/DropzoneInput/index.tsx index dbde50703..4907c8220 100644 --- a/packages/web-ui/src/ds/atoms/DropzoneInput/index.tsx +++ b/packages/web-ui/src/ds/atoms/DropzoneInput/index.tsx @@ -23,7 +23,6 @@ export function DropzoneInput({ const ref = useRef(null) const onClickZone = useCallback(() => { if (!ref.current) return - console.log('File input ref', ref.current) ref.current.click() }, [ref]) diff --git a/packages/web-ui/src/ds/atoms/Input/index.tsx b/packages/web-ui/src/ds/atoms/Input/index.tsx index 74d567aae..c2b0901f5 100644 --- a/packages/web-ui/src/ds/atoms/Input/index.tsx +++ b/packages/web-ui/src/ds/atoms/Input/index.tsx @@ -47,6 +47,7 @@ const Input = forwardRef(function Input( {...props} /> ) + if (props.hidden) return inputComp return (