Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-duport committed Jan 30, 2025
1 parent a29003d commit 19899a6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ export class RegisterAgencyToInclusionConnectUser extends TransactionalUseCase<
const agencyRights = await uow.agencyRepository.getAgenciesRightsByUserId(
user.id,
);
const alreadyHasRequestedAgencyRight =
agencyRights.filter((agencyRight) =>
agencyIds.includes(agencyRight.agencyId),
).length >= 1;
const alreadyHasRequestedAgencyRight = agencyRights.filter((agencyRight) =>
agencyIds.includes(agencyRight.agencyId),
).length;
if (alreadyHasRequestedAgencyRight) {
throw errors.user.alreadyHaveAgencyRights({
userId: user.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe("RegisterAgencyToInclusionConnectUser use case", () => {
userId: user.id,
});

expectToEqual(await uow.userRepository.users, [user]);
expectToEqual(uow.userRepository.users, [user]);
expectToEqual(uow.agencyRepository.agencies, [
toAgencyWithRights(agency1, {
[user.id]: { roles: ["to-review"], isNotifiedByEmail: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,17 @@ export function NoActiveAgencyRights({
</div>
<div className={fr.cx("fr-col-12", "fr-col-lg-10")}>
<h3>Vous travaillez ailleurs ?</h3>
{!showRegistrationForm && (
{showRegistrationForm ? (
<RegisterAgenciesForm currentUser={currentUser} />
) : (
<Button
onClick={() => {
setShowRegistrationForm(() => true);
setShowRegistrationForm(true);
}}
>
Demander l'accès à d'autre organismes
</Button>
)}
{showRegistrationForm && (
<RegisterAgenciesForm currentUser={currentUser} />
)}
</div>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,23 @@ export const RegisterAgenciesForm = ({
}) => {
const dispatch = useDispatch();
const [inputValue, setInputValue] = useState<string>("");
const inputElement = React.useRef<ElementRef<"input">>(null);
const agencySearchBySiretOrNameInput =
React.useRef<ElementRef<"input">>(null);

const [isAllChecked, setIsAllChecked] = useState<boolean>(false);
const [checkedAgencies, setCheckedAgencies] = useState<AgencyId[]>([]);
const [selectedAgencyIds, setSelectedAgencyIds] = useState<AgencyId[]>([]);

const onAgencySearchChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(event.currentTarget.value);
setSelectedAgencyIds([]);
setIsAllChecked(false);
dispatch(
agenciesSlice.actions.fetchAgencyOptionsRequested({
nameIncludes: event.currentTarget.value,
status: ["active", "from-api-PE"],
}),
);
};
return (
<>
<div className={fr.cx("fr-mt-4w", "fr-mb-2w")}>
Expand All @@ -40,20 +53,10 @@ export const RegisterAgenciesForm = ({
type: "search",
placeholder: "",
value: inputValue,
onChange: (event) => {
setInputValue(event.currentTarget.value);
setCheckedAgencies([]);
setIsAllChecked(false);
dispatch(
agenciesSlice.actions.fetchAgencyOptionsRequested({
nameIncludes: event.currentTarget.value,
status: ["active", "from-api-PE"],
}),
);
},
onChange: onAgencySearchChange,
onKeyDown: (event) => {
if (event.key === "Escape") {
inputElement.current?.blur();
agencySearchBySiretOrNameInput.current?.blur();
}
},
}}
Expand All @@ -76,8 +79,8 @@ export const RegisterAgenciesForm = ({
<div className={fr.cx("fr-col-12", "fr-col-md-8")}>
<strong>Résultats pour votre recherche "{inputValue}"</strong>
<p className={fr.cx("fr-hint-text")}>
{checkedAgencies.length}{" "}
{checkedAgencies.length <= 1
{selectedAgencyIds.length}{" "}
{selectedAgencyIds.length <= 1
? "organisme sélectionné"
: "organismes sélectionnés"}
</p>
Expand All @@ -88,19 +91,19 @@ export const RegisterAgenciesForm = ({
onClick={() => {
dispatch(
inclusionConnectedSlice.actions.registerAgenciesRequested({
agencies: checkedAgencies,
agencies: selectedAgencyIds,
feedbackTopic: "dashboard-agency-register-user",
}),
);
}}
disabled={checkedAgencies.length === 0}
disabled={selectedAgencyIds.length === 0}
>
Demander l'accès aux organismes sélectionnés
</Button>
</div>
<AgencyTable
checkedAgencies={checkedAgencies}
setCheckedAgencies={setCheckedAgencies}
checkedAgencies={selectedAgencyIds}
setCheckedAgencies={setSelectedAgencyIds}
isAllChecked={isAllChecked}
setIsAllChecked={setIsAllChecked}
currentUser={currentUser}
Expand Down
2 changes: 1 addition & 1 deletion front/src/app/pages/user/MyProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const MyProfile = (_: MyProfileProps) => {
return (
<>
<UserProfile
title={`${userDisplayed}`}
title={userDisplayed}
currentUser={currentUser}
userWithRights={currentUser}
editInformationsLink={getLinkToUpdateAccountInfo(
Expand Down

0 comments on commit 19899a6

Please sign in to comment.