mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-04 04:01:27 +00:00
chore: Application du linter
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { getGravatarUrl } from '@/utils/gravatar'; // Assurez-vous que cette fonction est définie pour générer les URLs Gravatar
|
||||
import { getRightStr } from '@/utils/rights'; // Fonction existante pour récupérer le nom des rôles
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
export default function RecipientInput({
|
||||
label,
|
||||
@ -8,6 +9,7 @@ export default function RecipientInput({
|
||||
setRecipients,
|
||||
searchRecipients, // Fonction pour effectuer la recherche
|
||||
establishmentId, // ID de l'établissement
|
||||
required = false, // Ajout de la prop required avec valeur par défaut
|
||||
}) {
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [suggestions, setSuggestions] = useState([]);
|
||||
@ -22,7 +24,7 @@ export default function RecipientInput({
|
||||
const results = await searchRecipients(establishmentId, value);
|
||||
setSuggestions(results);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la recherche des destinataires:', error);
|
||||
logger.error('Erreur lors de la recherche des destinataires:', error);
|
||||
setSuggestions([]);
|
||||
}
|
||||
} else {
|
||||
@ -37,8 +39,8 @@ export default function RecipientInput({
|
||||
handleSuggestionClick(suggestions[selectedIndex]);
|
||||
} else {
|
||||
const trimmedValue = inputValue.trim();
|
||||
if (trimmedValue && !recipients.some((r) => r.email === trimmedValue)) {
|
||||
setRecipients([...recipients, { email: trimmedValue }]);
|
||||
if (trimmedValue && !recipients.includes(trimmedValue)) {
|
||||
setRecipients([...recipients, trimmedValue]);
|
||||
setInputValue('');
|
||||
setSuggestions([]);
|
||||
}
|
||||
@ -57,39 +59,44 @@ export default function RecipientInput({
|
||||
};
|
||||
|
||||
const handleSuggestionClick = (suggestion) => {
|
||||
if (!recipients.some((r) => r.email === suggestion.email)) {
|
||||
setRecipients([...recipients, suggestion]);
|
||||
if (!recipients.includes(suggestion.email)) {
|
||||
setRecipients([...recipients, suggestion.email]);
|
||||
}
|
||||
setInputValue('');
|
||||
setSuggestions([]);
|
||||
};
|
||||
|
||||
const handleRemoveRecipient = (email) => {
|
||||
setRecipients(recipients.filter((recipient) => recipient.email !== email));
|
||||
setRecipients(recipients.filter((recipient) => recipient !== email));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm font-medium text-gray-700">{label}</label>
|
||||
<div className="flex flex-wrap items-center gap-2 p-2 border rounded">
|
||||
{recipients.map((recipient, index) => (
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
{label}
|
||||
{required && <span className="text-red-500 ml-1">*</span>}
|
||||
</label>
|
||||
<div
|
||||
className={`
|
||||
mt-1 flex flex-wrap items-center gap-2 border rounded-md
|
||||
border-gray-200 hover:border-gray-400 focus-within:border-gray-500
|
||||
transition-colors
|
||||
`}
|
||||
>
|
||||
{recipients.map((email, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="flex items-center bg-gray-100 text-gray-700 px-2 py-1 rounded-full"
|
||||
>
|
||||
<img
|
||||
src={getGravatarUrl(recipient.email)}
|
||||
alt={recipient.email}
|
||||
src={getGravatarUrl(email)}
|
||||
alt={email}
|
||||
className="w-6 h-6 rounded-full mr-2"
|
||||
/>
|
||||
<span className="mr-2">
|
||||
{recipient.first_name && recipient.last_name
|
||||
? `${recipient.first_name} ${recipient.last_name}`
|
||||
: recipient.email}
|
||||
</span>
|
||||
<span className="mr-2">{email}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleRemoveRecipient(recipient.email)}
|
||||
onClick={() => handleRemoveRecipient(email)}
|
||||
className="text-gray-500 hover:text-gray-700"
|
||||
>
|
||||
×
|
||||
@ -102,7 +109,8 @@ export default function RecipientInput({
|
||||
onChange={handleInputChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Rechercher des destinataires"
|
||||
className="flex-1 p-1 outline-none"
|
||||
className="flex-1 px-3 py-2 block w-full sm:text-sm border-none focus:ring-0 outline-none rounded-md"
|
||||
required={required}
|
||||
/>
|
||||
</div>
|
||||
{suggestions.length > 0 && (
|
||||
|
||||
Reference in New Issue
Block a user