diff --git a/backend/src/forms/forms.py b/backend/src/forms/forms.py
index f2e68e4..3d69f92 100644
--- a/backend/src/forms/forms.py
+++ b/backend/src/forms/forms.py
@@ -30,6 +30,31 @@ async def get_forms_filtered(
return service.get_all(session, seasons, productors, current_season, user)
+@router.get(
+ '/{_id}/preview-delete',
+ response_model=list[models.DeleteDependency]
+)
+async def preview_delete(
+ _id: int,
+ session: Session = Depends(get_session),
+ user: models.User = Depends(get_current_user),
+):
+ if not service.is_allowed(session, user, _id=_id):
+ raise HTTPException(
+ status_code=403,
+ detail=messages.Messages.not_allowed('forms', 'delete')
+ )
+ try:
+ result = service.get_delete_dependencies(
+ session,
+ _id
+ )
+ print(result)
+ except exceptions.FormNotFoundError as error:
+ raise HTTPException(status_code=404, detail=str(error)) from error
+ return result
+
+
@router.get('/{_id}', response_model=models.FormPublic)
async def get_form(
_id: int,
@@ -68,7 +93,7 @@ async def create_form(
@router.put('/{_id}', response_model=models.FormPublic)
async def update_form(
- _id: int,
+ _id: int,
form: models.FormUpdate,
user: models.User = Depends(get_current_user),
session: Session = Depends(get_session)
diff --git a/backend/src/forms/service.py b/backend/src/forms/service.py
index 23b8a1e..d62b832 100644
--- a/backend/src/forms/service.py
+++ b/backend/src/forms/service.py
@@ -107,6 +107,44 @@ def delete_one(session: Session, _id: int) -> models.FormPublic:
return result
+def get_delete_dependencies(
+ session: Session,
+ _id: int
+) -> list[models.DeleteDependency]:
+ statement = select(models.Form).where(models.Form.id == _id)
+ result = session.exec(statement)
+ form = result.first()
+ if not form:
+ raise exceptions.FormNotFoundError(messages.Messages.not_found('form'))
+ print(_id)
+ statement_shipment = (
+ select(models.Shipment)
+ .where(models.Shipment.form_id == _id)
+ .distinct()
+ )
+ statement_contracts = (
+ select(models.Contract)
+ .where(models.Contract.form_id == _id)
+ .distinct()
+ )
+ shipments = session.exec(statement_shipment).all()
+ contracts = session.exec(statement_contracts).all()
+ result = [
+ models.DeleteDependency(
+ name=sh.name,
+ id=sh.id,
+ type='shipment'
+ ) for sh in shipments
+ ] + [
+ models.DeleteDependency(
+ name=f'{co.firstname} {co.lastname}',
+ id=co.id,
+ type='contract'
+ ) for co in contracts
+ ]
+ return result
+
+
def is_allowed(
session: Session,
user: models.User,
diff --git a/backend/src/models.py b/backend/src/models.py
index c17e8f4..ab60a26 100644
--- a/backend/src/models.py
+++ b/backend/src/models.py
@@ -5,6 +5,12 @@ from typing import Optional
from sqlmodel import Column, Field, LargeBinary, Relationship, SQLModel
+class DeleteDependency(SQLModel):
+ id: int
+ name: str
+ type: str
+
+
class ContractType(SQLModel, table=True):
id: int | None = Field(
default=None,
diff --git a/backend/src/shipments/service.py b/backend/src/shipments/service.py
index 32792be..c49ef85 100644
--- a/backend/src/shipments/service.py
+++ b/backend/src/shipments/service.py
@@ -138,11 +138,7 @@ def is_allowed(
return False
if not _id:
statement = (
- select(models.Shipment)
- .join(
- models.Form,
- models.Shipment.form_id == models.Form.id
- )
+ select(models.Form)
.where(models.Form.id == shipment.form_id)
)
form = session.exec(statement).first()
@@ -162,4 +158,3 @@ def is_allowed(
.distinct()
)
return len(session.exec(statement).all()) > 0
-
diff --git a/frontend/locales/en.json b/frontend/locales/en.json
index 2d5c1b9..a9d74bf 100644
--- a/frontend/locales/en.json
+++ b/frontend/locales/en.json
@@ -84,6 +84,8 @@
"once all contracts downloaded, you can delete the form (to avoid new submissions) and hide it from the home page": "once all contracts downloaded, you can delete the form (to avoid new submissions) and hide it from the home page",
"by checking this option the form will be accessible publicly on the home page, only check it if everything is fine with your form": "by checking this option the form will be accessible publicly on the home page, only check it if everything is fine with your form",
"contracts": "contracts",
+ "contract": "contract",
+ "user": "user",
"hidden": "hidden",
"visible": "visible",
"minimum price for this shipment should be at least": "minimum price for this shipment should be at least",
@@ -179,6 +181,10 @@
"grams": "grams (g)",
"kilo": "kilograms (kg)",
"liter": "liters (L)",
+ "are you sure you want to delete": "are you sure you want to delete",
+ "this will also delete": "this will also delete",
+ "delete entity": "delete {{entity}}",
+ "delete": "delete",
"success": "success",
"success edit": "{{entity}} correctly edited",
"success create": "{{entity}} correctly created",
diff --git a/frontend/locales/fr.json b/frontend/locales/fr.json
index 0099a3d..1f8485a 100644
--- a/frontend/locales/fr.json
+++ b/frontend/locales/fr.json
@@ -81,6 +81,8 @@
"there is": "il y a",
"for this contract": "pour ce contrat.",
"remove shipment": "supprimer la livraison",
+ "contract": "contrat",
+ "user": "utilisateur·trice",
"productors": "producteur·trices",
"products": "produits",
"templates": "modèles",
@@ -179,6 +181,10 @@
"grams": "grammes (g)",
"kilo": "kilogrammes (kg)",
"liter": "litres (L)",
+ "are you sure you want to delete": "êtes vous sûr de vouloir supprimer",
+ "this will also delete": "cette action supprimera aussi",
+ "delete entity": "supprimer un {{entity}}",
+ "delete": "supprimer",
"success": "succès",
"success edit": "{{entity}} correctement édité",
"success create": "{{entity}} correctement créé",
diff --git a/frontend/src/components/DeleteModal/index.tsx b/frontend/src/components/DeleteModal/index.tsx
new file mode 100644
index 0000000..cf0c1d7
--- /dev/null
+++ b/frontend/src/components/DeleteModal/index.tsx
@@ -0,0 +1,76 @@
+import { t } from "@/config/i18n";
+import type { DeleteDependencies } from "@/services/resources/common";
+import { Button, Group, List, Modal, Text, type ModalBaseProps } from "@mantine/core";
+import { IconCancel, IconCheck } from "@tabler/icons-react";
+import { Link } from "react-router";
+
+export type DeleteModalProps = ModalBaseProps & {
+ handleSubmit: (id: number) => void;
+ entityType: string;
+ entity: {name: string, id: number};
+ dependencies: DeleteDependencies[];
+}
+
+export function DeleteModal({
+ opened,
+ onClose,
+ handleSubmit,
+ entityType,
+ entity,
+ dependencies
+}: DeleteModalProps) {
+ return (
+
+ {
+ dependencies?.map((dependency) => (
+
+ }
+