-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add staff impersonation (#1753)
- Loading branch information
1 parent
c091d8d
commit 4afe85e
Showing
21 changed files
with
445 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client"; | ||
|
||
import { Notice } from "@codegouvfr/react-dsfr/Notice"; | ||
import { useSession } from "next-auth/react"; | ||
|
||
import { Box } from "../design-system/base/Box"; | ||
|
||
export const ImpersonateNotice = () => { | ||
const session = useSession(); | ||
|
||
if (session.status !== "authenticated") return null; | ||
|
||
const isImpersonating = session.data.staff?.impersonating || false; | ||
|
||
if (!isImpersonating) return null; | ||
|
||
const { siren, label } = session.data.user.companies[0]; | ||
|
||
return ( | ||
<> | ||
<Notice | ||
style={{ position: "fixed", zIndex: 99999, width: "100%", marginTop: "-3.5rem" }} | ||
title={`Vous êtes actuellement dans la peau du Siren "${siren}" (${label}). Pour arrêter, rendez-vous sur la page d'admin.`} | ||
/> | ||
<Box mt="7w" /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use server"; | ||
|
||
import { entrepriseService } from "@api/core-domain/infra/services"; | ||
import { type Entreprise, EntrepriseServiceNotFoundError } from "@api/core-domain/infra/services/IEntrepriseService"; | ||
import { Siren } from "@common/core-domain/domain/valueObjects/Siren"; | ||
import { type ServerActionResponse } from "@common/utils/next"; | ||
|
||
import { CompanyErrorCodes } from "./companyErrorCodes"; | ||
|
||
export async function getCompany(siren: string): Promise<ServerActionResponse<Entreprise, CompanyErrorCodes>> { | ||
try { | ||
return { | ||
data: await entrepriseService.siren(new Siren(siren)), | ||
ok: true, | ||
}; | ||
} catch (error: unknown) { | ||
return { | ||
ok: false, | ||
error: error instanceof EntrepriseServiceNotFoundError ? CompanyErrorCodes.NOT_FOUND : CompanyErrorCodes.UNKNOWN, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum CompanyErrorCodes { | ||
NOT_FOUND, | ||
UNKNOWN, | ||
ABORTED = 999, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.