Skip to content

Commit

Permalink
feat: renamed rndtsDeclarationDelegation -> registryDelegation
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelFerrand committed Oct 10, 2024
1 parent 561f28e commit 3014a7e
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 95 deletions.
8 changes: 4 additions & 4 deletions front/src/Apps/Companies/CompanyDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import CompanyMembers from "./CompanyMembers/CompanyMembers";
import CompanyDigestSheetForm from "./CompanyDigestSheet/CompanyDigestSheet";
import { Tabs, TabsProps } from "@codegouvfr/react-dsfr/Tabs";
import { FrIconClassName } from "@codegouvfr/react-dsfr";
import { CompanyRndtsDeclarationDelegation } from "./CompanyRndtsDeclarationDelegation/CompanyRndtsDeclarationDelegation";
import { CompanyRegistryDelegation } from "./CompanyRegistryDelegation/CompanyRegistryDelegation";

export type TabContentProps = {
company: CompanyPrivate;
};

const RNDTS_FLAG = "REGISTRY_V2";
const REGISTRY_V2_FLAG = "REGISTRY_V2";

const buildTabs = (
company: CompanyPrivate
Expand All @@ -39,7 +39,7 @@ const buildTabs = (
const isAdmin = company.userRole === UserRole.Admin;

// RNDTS features protected by feature flag
const canViewRndtsFeatures = company.featureFlags.includes(RNDTS_FLAG);
const canViewRndtsFeatures = company.featureFlags.includes(REGISTRY_V2_FLAG);

const iconId = "fr-icon-checkbox-line" as FrIconClassName;
const tabs = [
Expand Down Expand Up @@ -82,7 +82,7 @@ const buildTabs = (
label: "Délégations RNDTS",
iconId
});
tabsContent["tab6"] = CompanyRndtsDeclarationDelegation;
tabsContent["tab6"] = CompanyRegistryDelegation;
}
if (isAdmin) {
tabs.push({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import "./companyRegistryDelegation.scss";
import { CompanyPrivate } from "@td/codegen-ui";
import { CompanyRegistryDelegationAsDelegator } from "./CompanyRegistryDelegationAsDelegator";
import { CompanyRegistryDelegationAsDelegate } from "./CompanyRegistryDelegationAsDelegate";

interface Props {
company: CompanyPrivate;
}

export const CompanyRegistryDelegation = ({ company }: Props) => {
return (
<>
<CompanyRegistryDelegationAsDelegator company={company} />
<CompanyRegistryDelegationAsDelegate company={company} />
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from "react";
import "./companyRndtsDeclarationDelegation.scss";
import "./companyRegistryDelegation.scss";
import { CompanyPrivate } from "@td/codegen-ui";
import { RndtsDeclarationDelegationsTable } from "./RndtsDeclarationDelegationsTable";
import { RegistryDelegationsTable } from "./RegistryDelegationsTable";

interface Props {
company: CompanyPrivate;
}

export const CompanyRndtsDeclarationDelegationAsDelegate = ({
company
}: Props) => {
export const CompanyRegistryDelegationAsDelegate = ({ company }: Props) => {
return (
<>
<h4>Délégataires</h4>
Expand All @@ -18,7 +16,7 @@ export const CompanyRndtsDeclarationDelegationAsDelegate = ({
registres RNDTS
</div>
<div>
<RndtsDeclarationDelegationsTable as="delegate" company={company} />
<RegistryDelegationsTable as="delegate" company={company} />
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { useState } from "react";
import "./companyRndtsDeclarationDelegation.scss";
import "./companyRegistryDelegation.scss";
import { CompanyPrivate, UserRole } from "@td/codegen-ui";
import Button from "@codegouvfr/react-dsfr/Button";
import { CreateRndtsDeclarationDelegationModal } from "./CreateRndtsDeclarationDelegationModal";
import { RndtsDeclarationDelegationsTable } from "./RndtsDeclarationDelegationsTable";
import { CreateRegistryDelegationModal } from "./CreateRegistryDelegationModal";
import { RegistryDelegationsTable } from "./RegistryDelegationsTable";

interface Props {
company: CompanyPrivate;
}

export const CompanyRndtsDeclarationDelegationAsDelegator = ({
company
}: Props) => {
export const CompanyRegistryDelegationAsDelegator = ({ company }: Props) => {
const isAdmin = company.userRole === UserRole.Admin;

const [isModalOpen, setIsModalOpen] = useState(false);
Expand All @@ -32,7 +30,7 @@ export const CompanyRndtsDeclarationDelegationAsDelegator = ({
className="fr-my-4v"
nativeButtonProps={{
type: "button",
"data-testid": "company-add-rndtsDeclarationDelegation"
"data-testid": "company-add-registryDelegation"
}}
disabled={isModalOpen}
onClick={() => setIsModalOpen(true)}
Expand All @@ -43,10 +41,10 @@ export const CompanyRndtsDeclarationDelegationAsDelegator = ({
)}

<div>
<RndtsDeclarationDelegationsTable as="delegator" company={company} />
<RegistryDelegationsTable as="delegator" company={company} />
</div>

<CreateRndtsDeclarationDelegationModal
<CreateRegistryDelegationModal
company={company}
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import {
CompanyPrivate,
Mutation,
MutationCreateRndtsDeclarationDelegationArgs
MutationCreateRegistryDelegationArgs
} from "@td/codegen-ui";
import { FieldError, useForm } from "react-hook-form";
import { Modal } from "../../../common/components";
Expand All @@ -16,9 +16,9 @@ import { datetimeToYYYYMMDD } from "../../Dashboard/Validation/BSPaoh/paohUtils"
import { startOfDay } from "date-fns";
import { useMutation } from "@apollo/client";
import {
CREATE_RNDTS_DECLARATION_DELEGATION,
RNDTS_DECLARATION_DELEGATIONS
} from "../../common/queries/rndtsDeclarationDelegation/queries";
CREATE_REGISTRY_DELEGATION,
REGISTRY_DELEGATIONS
} from "../../common/queries/registryDelegation/queries";
import toast from "react-hot-toast";

const displayError = (error: FieldError | undefined) => {
Expand Down Expand Up @@ -81,16 +81,16 @@ interface Props {
onClose: () => void;
}

export const CreateRndtsDeclarationDelegationModal = ({
export const CreateRegistryDelegationModal = ({
company,
onClose,
isOpen
}: Props) => {
const [createRndtsDeclarationDelegation, { loading }] = useMutation<
Pick<Mutation, "createRndtsDeclarationDelegation">,
MutationCreateRndtsDeclarationDelegationArgs
>(CREATE_RNDTS_DECLARATION_DELEGATION, {
refetchQueries: [RNDTS_DECLARATION_DELEGATIONS]
const [createRegistryDelegation, { loading }] = useMutation<
Pick<Mutation, "createRegistryDelegation">,
MutationCreateRegistryDelegationArgs
>(CREATE_REGISTRY_DELEGATION, {
refetchQueries: [REGISTRY_DELEGATIONS]
});

const validationSchema = getSchema();
Expand All @@ -114,7 +114,7 @@ export const CreateRndtsDeclarationDelegationModal = ({
};

const onSubmit = async input => {
await createRndtsDeclarationDelegation({
await createRegistryDelegation({
variables: {
input: {
...input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@ import React, { useState } from "react";
import {
CompanyPrivate,
Query,
RndtsDeclarationDelegation,
RndtsDeclarationDelegationStatus,
RegistryDelegation,
RegistryDelegationStatus,
UserRole
} from "@td/codegen-ui";
import { isDefinedStrict } from "../../../common/helper";
import { formatDateViewDisplay } from "../common/utils";
import classnames from "classnames";
import Pagination from "@codegouvfr/react-dsfr/Pagination";
import "./companyRndtsDeclarationDelegation.scss";
import "./companyRegistryDelegation.scss";
import { useQuery } from "@apollo/client";
import { RNDTS_DECLARATION_DELEGATIONS } from "../../common/queries/rndtsDeclarationDelegation/queries";
import { REGISTRY_DELEGATIONS } from "../../common/queries/registryDelegation/queries";
import Button from "@codegouvfr/react-dsfr/Button";
import { RevokeRndtsDeclarationDelegationModal } from "./RevokeRndtsDeclarationDelegationModal";
import { RevokeRegistryDelegationModal } from "./RevokeRegistryDelegationModal";

const getStatusLabel = (status: RndtsDeclarationDelegationStatus) => {
const getStatusLabel = (status: RegistryDelegationStatus) => {
switch (status) {
case RndtsDeclarationDelegationStatus.Ongoing:
case RegistryDelegationStatus.Ongoing:
return "EN COURS";
case RndtsDeclarationDelegationStatus.Incoming:
case RegistryDelegationStatus.Incoming:
return "À VENIR";
case RndtsDeclarationDelegationStatus.Closed:
case RegistryDelegationStatus.Closed:
return "CLÔTURÉE";
}
};

const getStatusBadge = (status: RndtsDeclarationDelegationStatus) => {
const getStatusBadge = (status: RegistryDelegationStatus) => {
return (
<p
className={classnames(`fr-badge fr-badge--sm fr-badge--no-icon`, {
"fr-badge--success":
status === RndtsDeclarationDelegationStatus.Ongoing,
"fr-badge--info": status === RndtsDeclarationDelegationStatus.Incoming,
"fr-badge--error": status === RndtsDeclarationDelegationStatus.Closed
"fr-badge--success": status === RegistryDelegationStatus.Ongoing,
"fr-badge--info": status === RegistryDelegationStatus.Incoming,
"fr-badge--error": status === RegistryDelegationStatus.Closed
})}
>
{getStatusLabel(status)}
Expand All @@ -60,16 +59,16 @@ interface Props {
company: CompanyPrivate;
}

export const RndtsDeclarationDelegationsTable = ({ as, company }: Props) => {
export const RegistryDelegationsTable = ({ as, company }: Props) => {
const [pageIndex, setPageIndex] = useState(0);
const [delegationToRevoke, setDelegationToRevoke] =
useState<RndtsDeclarationDelegation | null>(null);
useState<RegistryDelegation | null>(null);

const isAdmin = company.userRole === UserRole.Admin;

const { data, loading, refetch } = useQuery<
Pick<Query, "rndtsDeclarationDelegations">
>(RNDTS_DECLARATION_DELEGATIONS, {
Pick<Query, "registryDelegations">
>(REGISTRY_DELEGATIONS, {
skip: !company.orgId,
fetchPolicy: "network-only",
variables: {
Expand All @@ -80,9 +79,9 @@ export const RndtsDeclarationDelegationsTable = ({ as, company }: Props) => {
}
});

const totalCount = data?.rndtsDeclarationDelegations.totalCount;
const totalCount = data?.registryDelegations.totalCount;
const delegations =
data?.rndtsDeclarationDelegations.edges.map(edge => edge.node) ?? [];
data?.registryDelegations.edges.map(edge => edge.node) ?? [];

const PAGE_SIZE = 10;
const pageCount = totalCount ? Math.ceil(totalCount / PAGE_SIZE) : 0;
Expand Down Expand Up @@ -171,16 +170,15 @@ export const RndtsDeclarationDelegationsTable = ({ as, company }: Props) => {
<td>{getStatusBadge(status)}</td>
{isAdmin && (
<td>
{status !==
RndtsDeclarationDelegationStatus.Closed && (
{status !== RegistryDelegationStatus.Closed && (
<Button
priority="primary"
size="small"
className="fr-my-4v"
nativeButtonProps={{
type: "button",
"data-testid":
"company-revoke-rndtsDeclarationDelegation"
"company-revoke-registryDelegation"
}}
disabled={false}
onClick={() => setDelegationToRevoke(delegation)}
Expand Down Expand Up @@ -223,7 +221,7 @@ export const RndtsDeclarationDelegationsTable = ({ as, company }: Props) => {
</div>

{delegationToRevoke && (
<RevokeRndtsDeclarationDelegationModal
<RevokeRegistryDelegationModal
delegationId={delegationToRevoke.id}
to={as === "delegator" ? delegationToRevoke.delegate.name : null}
from={as === "delegate" ? delegationToRevoke.delegator.name : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from "react";
import {
Mutation,
MutationRevokeRndtsDeclarationDelegationArgs
} from "@td/codegen-ui";
import { Mutation, MutationRevokeRegistryDelegationArgs } from "@td/codegen-ui";
import { Modal } from "../../../common/components";
import Button from "@codegouvfr/react-dsfr/Button";
import { useMutation } from "@apollo/client";
import { REVOKE_RNDTS_DECLARATION_DELEGATION } from "../../common/queries/rndtsDeclarationDelegation/queries";
import { REVOKE_REGISTRY_DELEGATION } from "../../common/queries/registryDelegation/queries";
import toast from "react-hot-toast";
import { isDefined } from "../../../common/helper";

Expand All @@ -25,19 +22,19 @@ interface Props {
onClose: () => void;
}

export const RevokeRndtsDeclarationDelegationModal = ({
export const RevokeRegistryDelegationModal = ({
delegationId,
to,
from,
onClose
}: Props) => {
const [revokeRndtsDeclarationDelegation, { loading }] = useMutation<
Pick<Mutation, "revokeRndtsDeclarationDelegation">,
MutationRevokeRndtsDeclarationDelegationArgs
>(REVOKE_RNDTS_DECLARATION_DELEGATION);
const [revokeRegistryDelegation, { loading }] = useMutation<
Pick<Mutation, "revokeRegistryDelegation">,
MutationRevokeRegistryDelegationArgs
>(REVOKE_REGISTRY_DELEGATION);

const onRevoke = async () => {
await revokeRndtsDeclarationDelegation({
await revokeRegistryDelegation({
variables: {
delegationId
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { gql } from "@apollo/client";

export const CREATE_RNDTS_DECLARATION_DELEGATION = gql`
mutation createRndtsDeclarationDelegation(
$input: CreateRndtsDeclarationDelegationInput!
) {
createRndtsDeclarationDelegation(input: $input) {
export const CREATE_REGISTRY_DELEGATION = gql`
mutation createRegistryDelegation($input: CreateRegistryDelegationInput!) {
createRegistryDelegation(input: $input) {
id
updatedAt
delegate {
Expand All @@ -21,13 +19,13 @@ export const CREATE_RNDTS_DECLARATION_DELEGATION = gql`
}
`;

export const RNDTS_DECLARATION_DELEGATIONS = gql`
query rndtsDeclarationDelegations(
export const REGISTRY_DELEGATIONS = gql`
query registryDelegations(
$skip: Int
$first: Int
$where: RndtsDeclarationDelegationWhere
$where: RegistryDelegationWhere
) {
rndtsDeclarationDelegations(skip: $skip, first: $first, where: $where) {
registryDelegations(skip: $skip, first: $first, where: $where) {
totalCount
pageInfo {
startCursor
Expand Down Expand Up @@ -59,9 +57,9 @@ export const RNDTS_DECLARATION_DELEGATIONS = gql`
}
`;

export const REVOKE_RNDTS_DECLARATION_DELEGATION = gql`
mutation revokeRndtsDeclarationDelegation($delegationId: ID!) {
revokeRndtsDeclarationDelegation(delegationId: $delegationId) {
export const REVOKE_REGISTRY_DELEGATION = gql`
mutation revokeRegistryDelegation($delegationId: ID!) {
revokeRegistryDelegation(delegationId: $delegationId) {
id
isRevoked
status
Expand Down

0 comments on commit 3014a7e

Please sign in to comment.