Skip to content

Add edit and delete actions for sales entries#78

Open
Dipti1516 wants to merge 10 commits into
rushikesh-bobade:mainfrom
Dipti1516:feat/edit-delete-sales
Open

Add edit and delete actions for sales entries#78
Dipti1516 wants to merge 10 commits into
rushikesh-bobade:mainfrom
Dipti1516:feat/edit-delete-sales

Conversation

@Dipti1516

Copy link
Copy Markdown

Description

This PR adds edit and delete functionality for sales entries in the Sales Log.

Changes made

  • Added Edit Sale functionality
  • Added Delete Sale confirmation modal
  • Restored inventory item status to IN_STOCK when a sale is deleted
  • Added success toast notifications for create, edit, and delete actions
  • Improved the visibility of the Edit and Delete action buttons
  • Reused the existing Log Sale modal for editing sales

Related Issues

Fixes #28

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Screenshots

Screenshot (421)

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

@Dipti1516 is attempting to deploy a commit to the participationcorner2025-8967's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codesense Ai: This PR is too large to review automatically. A human maintainer will take a look!

@github-actions github-actions Bot added the ECSoC26 Required label for ECSOC Sentinel scoring label Jul 2, 2026
@rushikesh-bobade

Copy link
Copy Markdown
Owner

Hey @Dipti1516!

Welcome to the project, and thank you for taking on this issue! Your implementation of the Edit and Delete flows is really well thought out, and I especially love that you remembered to roll the inventory item status back to IN_STOCK when a sale is deleted. Great architectural thinking!

There are just a few things we need to polish up before we can merge this:

1. Revert package-lock.json (The massive diff)
It looks like your local environment updated the package-lock.json file, which added hundreds of lines to the PR and makes it hard to review. You can revert this file back to its clean state by running this in your terminal and pushing the commit:
git checkout origin/main -- package-lock.json

2. Critical Security Fix (IDOR Prevention)
In multi-tenant SaaS platforms like FlipTrack, we have to make sure users can only modify their own data. In your edit and delete server actions in app/routes/sales-log.tsx, the Prisma queries are missing a check for userId. Without this, a malicious user could technically edit or delete a sale belonging to someone else!
To fix this, update your where clauses to include the current user's ID:

await prisma.sale.update({
  where: { 
    id: saleId, 
    userId: user.id // <-- Add this!
  },
  // ...

Make sure to add userId: user.id to the where clause inside your prisma.sale.findUnique (for deleting) as well.

3. Cleanup
There's a leftover console.log("SALE:", s); inside the mapping function in app/blocks/sales-log/sales-table.tsx. Please remove that so we don't spam the browser console.

Push those quick fixes and we will get this merged. Really amazing work on the logic so far!

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

📝 Summary

The provided pull request diff introduces several changes to the sales log feature, including the addition of a delete sale modal, editing functionality for existing sales, and improvements to the sales table and log sale modal components. The changes also update the loader and action functions to handle the new functionality.

📂 Files Changed

  • app/blocks/sales-log/delete-sale-modal.tsx: New file added for the delete sale modal component.
  • app/blocks/sales-log/log-sale-modal.tsx: Updated to include editing functionality for existing sales.
  • app/blocks/sales-log/sales-table.module.css: Updated to include styles for the edit and delete buttons.
  • app/blocks/sales-log/sales-table.tsx: Updated to include the edit and delete buttons and to handle the new functionality.
  • app/routes/sales-log.tsx: Updated to include the new loader and action functions for handling the delete and edit functionality.

🎭 Code Poem

Changes abound in this code so fine,
New features added, and bugs defined.
The sales log feature now shines so bright,
With edit and delete, a wondrous sight.

🚨 Bugs & Architectural Violations * The `DeleteSaleModal` component does not include any accessibility attributes, such as `aria-hidden` or `role`. This should be added to ensure the component is accessible to all users. * The `LogSaleModal` component uses the `disabled` attribute on the select input when editing a sale. However, this attribute is not properly handled for screen readers. Consider using a more accessible approach, such as using a `readonly` attribute or a separate button to toggle the select input. * The `SalesTable` component uses the `IconEdit` and `IconTrash` components from `@tabler/icons-react`, but does not include any accessibility attributes. This should be added to ensure the icons are accessible to all users. * The `loader` function in `app/routes/sales-log.tsx` does not handle any potential errors that may occur when fetching the sales data. Consider adding error handling to ensure the application remains stable in case of errors. Looks solid otherwise!
💡 Suggestions & Best Practices * Consider adding a loading indicator to the `SalesTable` component to indicate when the data is being fetched. * The `LogSaleModal` component uses a lot of inline styles. Consider moving these styles to a separate CSS file to improve maintainability and readability. * The `DeleteSaleModal` component does not include any confirmation message before deleting a sale. Consider adding a confirmation message to ensure the user intends to delete the sale. * The `loader` function in `app/routes/sales-log.tsx` fetches the sales data and inventory data separately. Consider combining these into a single query to improve performance. * The `action` function in `app/routes/sales-log.tsx` handles the edit and delete functionality. Consider breaking this out into separate functions to improve readability and maintainability.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

📝 Summary

The provided pull request diff introduces several changes to the sales log feature, including the addition of a delete sale modal, editing functionality for existing sales, and improvements to the sales table and log sale modal components. The changes also update the loader and action functions to handle the new functionality.

📂 Files Changed

  • app/blocks/sales-log/delete-sale-modal.tsx: A new file containing the DeleteSaleModal component.
  • app/blocks/sales-log/log-sale-modal.tsx: Updates to the LogSaleModal component to support editing existing sales.
  • app/blocks/sales-log/sales-table.module.css: Adds new CSS classes for the edit and delete buttons.
  • app/blocks/sales-log/sales-table.tsx: Updates to the SalesTable component to include edit and delete buttons.
  • app/routes/sales-log.tsx: Updates to the loader and action functions to handle the new functionality.

🎭 Code Poem

Changes abound, with features so fine,
Delete and edit, a sales log divine.
Modals and tables, with buttons so bright,
A sales log experience, both day and night.

🚨 Bugs & Architectural Violations The provided code seems to follow the critical codebase architecture and rules. However, there are a few potential issues: * The `DeleteSaleModal` component does not include any accessibility attributes, such as `aria-hidden` or `role`. * The `LogSaleModal` component uses `useState` to store the sale price, selected item ID, and sale date. However, it does not handle cases where the sale data is not available or is invalid. * The `SalesTable` component uses `onClick` events to handle the edit and delete buttons. However, it does not provide any feedback to the user when the buttons are clicked. * The `loader` function returns a serialized version of the sales data, but it does not handle cases where the data is not available or is invalid. Looks solid, but these potential issues should be addressed.
💡 Suggestions & Best Practices * Consider adding accessibility attributes to the `DeleteSaleModal` component. * Add error handling to the `LogSaleModal` component to handle cases where the sale data is not available or is invalid. * Provide feedback to the user when the edit and delete buttons are clicked in the `SalesTable` component. * Consider adding validation to the `loader` function to handle cases where the data is not available or is invalid. * Use a more robust way to handle the sale data, such as using a state management library or a more robust data storage solution. * Consider adding a loading indicator to the `SalesTable` component to handle cases where the data is being loaded. * Use a more consistent naming convention throughout the codebase.

@Dipti1516

Copy link
Copy Markdown
Author

Hii @rushikesh-bobade , Thanks for the review! I've addressed all the requested changes, including reverting package-lock.json, adding ownership checks to the edit and delete actions, and removing the leftover console.log. I'd appreciate another review when you have time. Thanks!

@rushikesh-bobade

Copy link
Copy Markdown
Owner

@Dipti1516 Awesome job, the IDOR security fixes look perfect! Thank you!

You probably noticed the branch has merge conflicts now. This is just because we merged another PR recently that added platformFee and shippingCost fields to the exact same sales files you're working in.

To fix it, just run git pull origin main locally and resolve the conflicts in VS Code. Just make sure to keep their new fee inputs alongside your new Edit/Delete buttons.

Let me know if you run into any Git trouble and I can help you out!

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codesense Ai: This PR is too large to review automatically. A human maintainer will take a look!

@rushikesh-bobade

Copy link
Copy Markdown
Owner

Hi @Dipti1516,

Thanks for resolving those conflicts! The IDOR security fixes look perfect, and the CI typecheck passed successfully.

However, I did a deep code review and noticed two critical bugs that accidentally slipped in while you were resolving the Git merge conflicts in VS Code:

1. Missing UI Inputs

In app/blocks/sales-log/log-sale-modal.tsx, it looks like the Git conflict resolution accidentally deleted the salePrice and saleDate inputs! Without these, the form submits $0.00.
Please re-add the Sale Price and Sale Date inputs right above the Platform Fee inputs in the modal UI.

2. Missing Backend Update Fields

In app/routes/sales-log.tsx, inside your new intent === "edit" block (around line 160), you are not extracting platformFee and shippingCost from formData, and they are missing from the prisma.sale.update call. Because of this, if a user edits a sale and changes the fees, the server will ignore their changes!
Please make sure to extract platformFee and shippingCost from formData and pass them into the prisma.sale.update data object.

Once you restore those inputs and add the missing backend fields, we are completely good to merge! Let me know if you need any help finding where they go!

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codesense Ai: This PR is too large to review automatically. A human maintainer will take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ECSoC26 Required label for ECSOC Sentinel scoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Edit & Delete Actions for Sales Entries

2 participants