import React from "react"; import { EyeFilled, EyeOutlined, UserOutlined } from "@ant-design/icons"; import { Avatar, Button, Divider, List, Popover, Select, Tooltip, Typography } from "antd"; import { useTranslation } from "react-i18next"; import EmployeeSearchSelectComponent from "../../components/employee-search-select/employee-search-select.component.jsx"; import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component.jsx"; import { BiSolidTrash } from "react-icons/bi"; const { Text } = Typography; export default function JobWatcherToggleComponent({ jobWatchers, isWatching, watcherLoading, adding, removing, open, setOpen, selectedWatcher, setSelectedWatcher, selectedTeam, bodyshop, Enhanced_Payroll, handleToggleSelf, handleRemoveWatcher, handleWatcherSelect, handleTeamSelect, isEmployee }) { const { t } = useTranslation(); const handleRenderItem = (watcher) => { // Check if watcher is defined and has user_email if (!watcher || !watcher.user_email) { return null; // Skip rendering invalid watchers } const employee = bodyshop?.employees?.find((e) => e.user_email === watcher.user_email); const displayName = employee ? `${employee.first_name} ${employee.last_name}` : watcher.user_email; return ( } onClick={() => handleRemoveWatcher(watcher.user_email)} disabled={adding || removing} // Optional: Disable button during mutations > {t("notifications.actions.remove")} ]} > } />} title={{displayName}} description={watcher.user_email} /> ); }; const popoverContent = (
]} > {t("notifications.labels.watching-issue")} {!isEmployee && ( {t("notifications.tooltips.not-employee")} )} {watcherLoading ? ( ) : jobWatchers && jobWatchers.length > 0 ? ( ) : ( {t("notifications.labels.no-watchers")} )} {t("notifications.labels.add-watchers")} e.user_email && // Ensure user_email is not null or undefined e.active && // Ensure employee is active jobWatchers.every((w) => w.user_email !== e.user_email) // Ensure not already a watcher ) || [] } placeholder={t("notifications.labels.employee-search")} value={selectedWatcher} showEmail={true} onChange={(value) => { setSelectedWatcher(value); handleWatcherSelect(value); }} /> {Enhanced_Payroll && bodyshop?.employee_teams?.length > 0 && ( <> {t("notifications.labels.add-watchers-team")}