diff --git a/packages/app/src/api/core-domain/useCases/SaveDeclaration.ts b/packages/app/src/api/core-domain/useCases/SaveDeclaration.ts
index e2f90e3c0..ed64bb4d9 100644
--- a/packages/app/src/api/core-domain/useCases/SaveDeclaration.ts
+++ b/packages/app/src/api/core-domain/useCases/SaveDeclaration.ts
@@ -23,6 +23,7 @@ import { type IDeclarationRepo } from "../repo/IDeclarationRepo";
interface Input {
declaration: CreateDeclarationDTO;
+ override?: boolean;
}
export class SaveDeclaration implements UseCase {
@@ -31,7 +32,7 @@ export class SaveDeclaration implements UseCase {
private readonly entrepriseService: IEntrepriseService,
) {}
- public async execute({ declaration: dto }: Input): Promise {
+ public async execute({ declaration: dto, override }: Input): Promise {
const now = new Date();
const siren = dto.entreprise?.entrepriseDéclarante?.siren;
@@ -242,7 +243,7 @@ export class SaveDeclaration implements UseCase {
if (found) {
const olderThanOneYear = isAfter(new Date(), add(found.declaredAt, { years: 1 }));
- if (olderThanOneYear) {
+ if (olderThanOneYear && !override) {
throw new SaveDeclarationOverOneYearError("Déclaration is older than one year.");
}
declaration = Declaration.fromJson({
diff --git a/packages/app/src/app/(default)/index-egapro/declaration/AlertExistingDeclaration.tsx b/packages/app/src/app/(default)/index-egapro/declaration/AlertExistingDeclaration.tsx
index 671f40481..e1efe5062 100644
--- a/packages/app/src/app/(default)/index-egapro/declaration/AlertExistingDeclaration.tsx
+++ b/packages/app/src/app/(default)/index-egapro/declaration/AlertExistingDeclaration.tsx
@@ -7,16 +7,20 @@ import { config } from "@common/config";
import { useHasMounted } from "@components/utils/ClientOnly";
import { useDeclarationFormManager } from "@services/apiClient/useDeclarationFormManager";
import { add, isAfter } from "date-fns";
+import { useSession } from "next-auth/react";
export const AlertExistingDeclaration = () => {
const { formData } = useDeclarationFormManager();
const hasMounted = useHasMounted();
+ const session = useSession();
const declarationDate = formData["declaration-existante"].date;
if (!hasMounted || !declarationDate) return null;
- const olderThanOneYear = isAfter(new Date(), add(new Date(declarationDate), { years: 1 }));
+ const olderThanOneYear = session?.data?.staff
+ ? false
+ : isAfter(new Date(), add(new Date(declarationDate), { years: 1 }));
return (
) => {
+ const session = useSession();
const router = useRouter();
const { setStatus, saveFormData, resetFormData } = useDeclarationFormManager();
const date = déclaration["declaration-existante"].date;
- const olderThanOneYear = date === undefined || isAfter(new Date(), add(new Date(date), { years: 1 }));
+ const olderThanOneYear = session?.data?.staff
+ ? false
+ : date === undefined || isAfter(new Date(), add(new Date(date), { years: 1 }));
const saveAndGoNext = async (
{ siren, annéeIndicateurs }: { annéeIndicateurs: number; siren: string },
formData: DeclarationDTO,
diff --git a/packages/app/src/app/(default)/index-egapro/declaration/[siren]/[year]/page.tsx b/packages/app/src/app/(default)/index-egapro/declaration/[siren]/[year]/page.tsx
index 833ffa01b..8e9957900 100644
--- a/packages/app/src/app/(default)/index-egapro/declaration/[siren]/[year]/page.tsx
+++ b/packages/app/src/app/(default)/index-egapro/declaration/[siren]/[year]/page.tsx
@@ -85,7 +85,9 @@ const RecapPage = async ({ params: { siren, year: strYear } }: NextServerPagePro
const canEdit = canEditSiren(session?.user)(siren);
if (!declarationDate) return ;
- const olderThanOneYear = isAfter(new Date(), add(new Date(declarationDate), { years: 1 }));
+ const olderThanOneYear = session?.user?.staff
+ ? false
+ : isAfter(new Date(), add(new Date(declarationDate), { years: 1 }));
return (
<>
diff --git a/packages/app/src/app/(default)/index-egapro/declaration/actions.ts b/packages/app/src/app/(default)/index-egapro/declaration/actions.ts
index 761a6fdac..fd1e418bf 100644
--- a/packages/app/src/app/(default)/index-egapro/declaration/actions.ts
+++ b/packages/app/src/app/(default)/index-egapro/declaration/actions.ts
@@ -34,7 +34,7 @@ export async function getDeclaration(siren: string, year: number) {
export async function saveDeclaration(
declaration: CreateDeclarationDTO,
): Promise> {
- await assertServerSession({
+ const session = await assertServerSession({
owner: {
check: declaration.commencer?.siren || "",
message: "Not authorized to save declaration for this Siren.",
@@ -48,7 +48,7 @@ export async function saveDeclaration(
try {
const useCase = new SaveDeclaration(declarationRepo, entrepriseService);
- await useCase.execute({ declaration });
+ await useCase.execute({ declaration, override: session?.user?.staff });
const receiptUseCase = new SendDeclarationReceipt(declarationRepo, globalMailerService, jsxPdfService);
diff --git a/packages/app/src/app/(default)/representation-equilibree/[siren]/[year]/page.tsx b/packages/app/src/app/(default)/representation-equilibree/[siren]/[year]/page.tsx
index 132d277c0..cdc83d9c6 100644
--- a/packages/app/src/app/(default)/representation-equilibree/[siren]/[year]/page.tsx
+++ b/packages/app/src/app/(default)/representation-equilibree/[siren]/[year]/page.tsx
@@ -54,7 +54,9 @@ const RepEqPage = async ({ params: { siren, year: strYear } }: NextServerPagePro
const session = await getServerSession(authConfig);
const isOwner = !!session?.user.companies.some(company => company.siren === siren) || session?.user.staff;
- const olderThanOneYear = isAfter(new Date(), add(new Date(repEq.declaredAt), { years: 1 }));
+ const olderThanOneYear = session?.user?.staff
+ ? false
+ : isAfter(new Date(), add(new Date(repEq.declaredAt), { years: 1 }));
const monCompteProHost = monCompteProProvider.issuer;
return (