Skip to content

Commit

Permalink
add extract-report functionality to run after project or file create
Browse files Browse the repository at this point in the history
  • Loading branch information
jojortz committed Aug 23, 2024
1 parent 2e8a70d commit 08549a7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
24 changes: 24 additions & 0 deletions app/actions/sustainabilityReport/extractReportContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import axios from 'axios';

interface IParams {
userId: string;
projectId: string;
reportIds: string[];
}

export const extractReportContent = async ({ userId, projectId, reportIds }: IParams) => {
const data = {
userId: userId,
projectId: projectId,
reportIds: reportIds,
};
return await axios
.post(process.env.NEXT_PUBLIC_PORTFOLIO_INSIGHT_API_URL + '/extract-content', data)
.then((response) => {
return response.data;
})
.catch((error) => {
console.error('Error adding attribute. Please try again.');
throw error;
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import Heading from '../../Heading';
import { toast } from 'react-hot-toast';
import Dropzone from '../../SustainabilityReport/Dropzone';
import useSustainabilityStore from '@/app/hooks/sustainabilityReport/sustainabilityReportStore';
import { CloudArrowUp } from '@phosphor-icons/react';
import { CloudArrowUp, FileMagnifyingGlass } from '@phosphor-icons/react';
import { uploadFile } from '@/app/actions/sustainabilityReport/uploadFile';
import { AxiosError } from 'axios';
import useFetchSustainabilityData from '@/app/hooks/sustainabilityReport/useFetchSustainabilityData';
import { FieldValues, SubmitHandler, useForm } from 'react-hook-form';
import { extractReportContent } from '@/app/actions/sustainabilityReport/extractReportContent';

const SustainabilityReportAddFileModal = () => {
const SustainabilityReportAddFileModal = useSustainabilityReportAddFileModal();
Expand All @@ -40,6 +41,18 @@ const SustainabilityReportAddFileModal = () => {
);

console.log('Uploads complete', uploadResponses);
SustainabilityReportAddFileModal.setAddFileModalState(AddFileModalState.EXTRACTING_CONTENT);
console.log('Extracting content:', reportsToAdd);

// Capture responses from uploadFile
const extractionResponse = await extractReportContent({
projectId: SustainabilityReportAddFileModal.projectId,
userId: userId,
reportIds: uploadResponses.map((response) => response.reportId),
});

console.log('Extraction complete complete', extractionResponse);
fetchAttributesThenProjects();
await fetchAttributesThenProjects();
} catch (error) {
if (error instanceof AxiosError) {
Expand Down Expand Up @@ -102,6 +115,12 @@ const SustainabilityReportAddFileModal = () => {
<CloudArrowUp size={40} className="animate-pulse" />
</div>
)}
{SustainabilityReportAddFileModal.addFileModalState === AddFileModalState.EXTRACTING_CONTENT && (
<div className="flex flex-col justify-center items-center gap-4 text-xl">
Extracting Content
<FileMagnifyingGlass size={40} className="animate-pulse" />
</div>
)}
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import Heading from '../../Heading';
import { toast } from 'react-hot-toast';
import Dropzone from '../../SustainabilityReport/Dropzone';
import useSustainabilityStore from '@/app/hooks/sustainabilityReport/sustainabilityReportStore';
import { Blueprint, CloudArrowUp } from '@phosphor-icons/react';
import { Blueprint, CloudArrowUp, FileMagnifyingGlass } from '@phosphor-icons/react';
import { uploadFile } from '@/app/actions/sustainabilityReport/uploadFile';
import { AxiosError } from 'axios';
import useFetchSustainabilityData from '@/app/hooks/sustainabilityReport/useFetchSustainabilityData';
import { addProject } from '@/app/actions/sustainabilityReport/addProject';
import { FieldValues, SubmitHandler, useForm } from 'react-hook-form';
import { Input, Textarea } from '@material-tailwind/react';
import { extractReportContent } from '@/app/actions/sustainabilityReport/extractReportContent';

const SustainabilityReportProjectModal = () => {
const SustainabilityReportProjectModal = useSustainabilityReportProjectModal();
Expand Down Expand Up @@ -59,6 +60,17 @@ const SustainabilityReportProjectModal = () => {
);

console.log('Uploads complete', uploadResponses);
SustainabilityReportProjectModal.setProjectModalState(ProjectModalState.EXTRACTING_CONTENT);
console.log('Extracting content:', reportsToAdd);

// Capture responses from uploadFile
const extractionResponse = await extractReportContent({
projectId: projectResponse.projectId,
userId: userId,
reportIds: uploadResponses.map((response) => response.reportId),
});

console.log('Extraction complete complete', extractionResponse);
fetchAttributesThenProjects();
} catch (error) {
if (error instanceof AxiosError) {
Expand Down Expand Up @@ -136,6 +148,12 @@ const SustainabilityReportProjectModal = () => {
<CloudArrowUp size={40} className="animate-pulse" />
</div>
)}
{SustainabilityReportProjectModal.projectModalState === ProjectModalState.EXTRACTING_CONTENT && (
<div className="flex flex-col justify-center items-center gap-4 text-xl">
Extracting Content
<FileMagnifyingGlass size={40} className="animate-pulse" />
</div>
)}
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { create } from 'zustand';
export enum AddFileModalState {
ADD_FILES,
UPLOADING,
EXTRACTING_CONTENT,
SUCCESS,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum ProjectModalState {
ADD_FILES,
CREATING_PROJECT,
UPLOADING,
EXTRACTING_CONTENT,
SUCCESS,
}

Expand Down

0 comments on commit 08549a7

Please sign in to comment.