add option to delete location in all subsequent months
- Added toggle in LocationDeleteForm for deleting locations from future months (disabled by default) - Modified deleteLocationById action to support batch deletion across subsequent months - When enabled, deletes all locations with same name in current and future months/years - Only deletes user's own locations with proper data isolation - Added translations for toggle text in Croatian and English - Removed unused imports and variables to fix TypeScript warnings - Uses efficient MongoDB deleteMany operation for bulk deletions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -302,7 +302,7 @@ export const fetchLocationById = async (locationID:string) => {
|
||||
return(billLocation);
|
||||
};
|
||||
|
||||
export const deleteLocationById = withUser(async (user:AuthenticatedUser, locationID:string, yearMonth:YearMonth) => {
|
||||
export const deleteLocationById = withUser(async (user:AuthenticatedUser, locationID:string, yearMonth:YearMonth, _prevState:any, formData: FormData) => {
|
||||
|
||||
noStore();
|
||||
|
||||
@@ -310,8 +310,35 @@ export const deleteLocationById = withUser(async (user:AuthenticatedUser, locati
|
||||
|
||||
const { id: userId } = user;
|
||||
|
||||
// find a location with the given locationID
|
||||
await dbClient.collection<BillingLocation>("lokacije").deleteOne({ _id: locationID, userId });
|
||||
const deleteInSubsequentMonths = formData.get('deleteInSubsequentMonths') === 'on';
|
||||
|
||||
if (deleteInSubsequentMonths) {
|
||||
// Get the location name first to find all locations with the same name
|
||||
const location = await dbClient.collection<BillingLocation>("lokacije")
|
||||
.findOne({ _id: locationID, userId });
|
||||
|
||||
if (location) {
|
||||
// Delete all locations with the same name in current and subsequent months
|
||||
await dbClient.collection<BillingLocation>("lokacije").deleteMany({
|
||||
userId,
|
||||
name: location.name,
|
||||
$or: [
|
||||
{ "yearMonth.year": { $gt: yearMonth.year } },
|
||||
{
|
||||
"yearMonth.year": yearMonth.year,
|
||||
"yearMonth.month": { $gte: yearMonth.month }
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Delete only the specific location (current behavior)
|
||||
await dbClient.collection<BillingLocation>("lokacije").deleteOne({ _id: locationID, userId });
|
||||
}
|
||||
|
||||
await gotoHome(yearMonth)
|
||||
await gotoHome(yearMonth);
|
||||
|
||||
return {
|
||||
message: null
|
||||
};
|
||||
})
|
||||
Reference in New Issue
Block a user