Repository navigation
integrate description generation to donor offer creation + bug fixes #190
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "GeneralItem" ADD COLUMN "description" TEXT; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| } from "@/util/errors"; | ||
| import FileService from "@/services/fileService"; | ||
| import { tableParamsSchema } from "@/schema/tableParams"; | ||
| import { DescriptionService } from "@/services/descriptionService"; | ||
|
|
||
| export async function POST(req: NextRequest) { | ||
| try { | ||
|
|
@@ -24,16 +25,29 @@ export async function POST(req: NextRequest) { | |
| "You are not allowed to create donor offers" | ||
| ); | ||
| } | ||
|
|
||
| const params = req.nextUrl.searchParams; | ||
| const formData = await req.formData(); | ||
| const file = formData.get("file") as File | null; | ||
| const preview = formData.get("preview") === "true"; | ||
| const preview = params.get("preview") === "true"; | ||
|
|
||
| if (!file) { | ||
| throw new ArgumentError("File is required"); | ||
| } | ||
|
|
||
| const parsedFileData = await FileService.parseDonorOfferFile(file); | ||
| const itemDescriptionInput = parsedFileData.data.map((item) => ({ | ||
| title: item["title"] as string, | ||
| type: item["type"] as string, | ||
| unitType: item["unitType"] as string, | ||
| })); | ||
|
|
||
| const descriptions = | ||
| await DescriptionService.getOrGenerateDescriptions(itemDescriptionInput); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: No error handling if |
||
|
|
||
| parsedFileData.data.forEach((item, index) => { | ||
| item.description = descriptions[index]; | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: If |
||
|
|
||
| const result = await DonorOfferService.createDonorOffer( | ||
| formData, | ||
| parsedFileData, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,8 +47,9 @@ export default function CreateDonorOfferPage() { | |
| handleFileChange, | ||
| resetUpload: resetFileUpload, | ||
| } = useFileUpload<{ donorOfferItems: DonorOfferItem[] }>({ | ||
| previewEndpoint: "/api/donorOffers/create?preview=true", | ||
| previewEndpoint: "/api/donorOffers?preview=true", | ||
| onSuccess: (result) => { | ||
| console.log(result); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Remove debug console.log before merging |
||
| setData(result.donorOfferItems); | ||
| }, | ||
| validateBeforeUpload: () => { | ||
|
|
@@ -93,7 +94,7 @@ export default function CreateDonorOfferPage() { | |
|
|
||
| const resetUpload = () => { | ||
| resetFileUpload(); | ||
|
|
||
| setPreview(false); | ||
| setIsSuccess(false); | ||
| setIsError(false); | ||
|
|
@@ -119,7 +120,7 @@ export default function CreateDonorOfferPage() { | |
| }); | ||
|
|
||
| try { | ||
| await apiClient.post("/api/donorOffers/create", { | ||
| await apiClient.post("/api/donorOffers", { | ||
| body: formData, | ||
| }); | ||
| setIsSuccess(true); | ||
|
|
@@ -264,7 +265,9 @@ export default function CreateDonorOfferPage() { | |
| <DonorOfferErrorModal | ||
| setErrorOpen={setIsError} | ||
| resetUpload={resetUpload} | ||
| errors={["An error occurred while creating the donor offer. Please try again."]} | ||
| errors={[ | ||
| "An error occurred while creating the donor offer. Please try again.", | ||
| ]} | ||
| /> | ||
| )} | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ export type DonorOfferItem = { | |
| hfhShippingNumber?: string; | ||
| visible?: boolean; | ||
| notes?: string; | ||
| description?: string; | ||
| }; | ||
|
|
||
| interface PreviewTableProps { | ||
|
|
@@ -46,6 +47,7 @@ export const PreviewTable = ({ data, final }: PreviewTableProps) => ( | |
| "Visibility", | ||
| "Comment", | ||
| ]), | ||
| "Description", | ||
| ]} | ||
| rows={data.map((item) => ({ | ||
| cells: [ | ||
|
|
@@ -68,6 +70,7 @@ export const PreviewTable = ({ data, final }: PreviewTableProps) => ( | |
| item.visible ? "Visible" : "Hidden", | ||
| item.notes, | ||
| ]), | ||
| item.description, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: description can be undefined - should display fallback like 'N/A' or 'Generating...' instead of blank cell |
||
| ], | ||
| }))} | ||
| /> | ||
|
|
||
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.
logic: Missing validation for required fields. If
title,type, orunitTypeare undefined/null inparsedFileData.data, this will pass invalid data toDescriptionService