creating file key to upload to

This commit is contained in:
Khalim Conn-Kowlessar 2024-11-20 16:08:31 +00:00
parent eab898fb83
commit 325387b743

View file

@ -1,7 +1,7 @@
"use client";
import { Dialog, Transition, Menu } from "@headlessui/react";
import { useState, Fragment, useEffect } from "react";
import { useState, Fragment, useEffect, useMemo } from "react";
import { Input } from "@/app/shadcn_components/ui/input";
import { Button } from "@/app/shadcn_components/ui/button";
import { Float } from "@headlessui-float/react";
@ -139,6 +139,13 @@ async function generatePresignedUrl({
return response.json();
}
function generateS3Keys(userId: string, portfolioId: string) {
const timestamp = new Date().toISOString().replace(/[:.-]/g, "");
const assetListFileKey = `${userId}/${portfolioId}/${timestamp}/asset_list.csv`;
const valuationDataFileKey = `${userId}/${portfolioId}/${timestamp}/valuation_data.csv`;
return { assetListFileKey, valuationDataFileKey };
}
function useCreateRemoteAssessment({ portfolioId }: { portfolioId: string }) {
// 1) We want to upload the asset data. To do this, we format the asset data, generate a presigned URL, and upload the data to S3.
// 2) We then want to upload valuation data. To do this, we format the valuation data, generate a presigned URL, and upload the data to S3.
@ -148,7 +155,11 @@ function useCreateRemoteAssessment({ portfolioId }: { portfolioId: string }) {
const session = useSession();
const userId = String(session.data?.user.dbId);
const fileKey = "8/-1/asset_list.csv";
const { assetListFileKey, valuationDataFileKey } = useMemo(
() => generateS3Keys(userId, portfolioId),
[userId, portfolioId]
);
const {
mutate: mutatePresignedUrl,
@ -165,7 +176,7 @@ function useCreateRemoteAssessment({ portfolioId }: { portfolioId: string }) {
});
function handleSubmit() {
mutatePresignedUrl({ userId, portfolioId, fileKey });
mutatePresignedUrl({ userId, portfolioId, fileKey: assetListFileKey });
console.log("SUCCESS"); // This is where we would want to trigger some kind of use feedback
}