-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
260 additions
and
230 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useCallback } from "react"; | ||
import { RecipientType } from "@/hooks/useBrevoRecipients"; | ||
|
||
interface Recipient { | ||
id: RecipientType; | ||
label: string; | ||
column: "left" | "right"; | ||
} | ||
|
||
const RECIPIENTS: Recipient[] = [ | ||
{ id: "jeunes", label: "Jeunes", column: "left" }, | ||
{ id: "referents", label: "Référents de classes", column: "left" }, | ||
{ id: "chefs-etablissement", label: "Chefs d'établissement", column: "left" }, | ||
{ id: "representants", label: "Représentants légaux", column: "right" }, | ||
{ id: "chefs-centres", label: "Chefs de centres", column: "right" }, | ||
{ id: "administrateurs", label: "Coordinateurs CLE", column: "right" }, | ||
] as const; | ||
|
||
export const DEFAULT_SELECTED_RECIPIENTS = ["jeunes", "representants"] as const; | ||
|
||
interface RecipientsSelectionProps { | ||
selectedRecipients: RecipientType[]; | ||
onToggleRecipient: (recipientId: RecipientType) => void; | ||
error?: string; | ||
} | ||
|
||
export const RecipientsSelection = ({ selectedRecipients, onToggleRecipient, error }: RecipientsSelectionProps) => { | ||
const renderColumn = useCallback( | ||
(column: "left" | "right") => ( | ||
<div className="space-y-3"> | ||
{RECIPIENTS.filter((recipient) => recipient.column === column).map((recipient) => ( | ||
<label key={recipient.id} className="flex items-center space-x-3"> | ||
<input | ||
type="checkbox" | ||
checked={selectedRecipients.includes(recipient.id)} | ||
onChange={() => onToggleRecipient(recipient.id)} | ||
className={`w-4 h-4 text-blue-600 ${error ? "border-red-500" : ""}`} | ||
/> | ||
<span>{recipient.label}</span> | ||
</label> | ||
))} | ||
</div> | ||
), | ||
[selectedRecipients, onToggleRecipient, error], | ||
); | ||
|
||
return ( | ||
<div> | ||
<div className="grid grid-cols-2 gap-x-8 gap-y-3"> | ||
{renderColumn("left")} | ||
{renderColumn("right")} | ||
</div> | ||
{error && <span className="text-red-500 text-sm mt-1">{error}</span>} | ||
</div> | ||
); | ||
}; |
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.