|
| 1 | +import { useEffect } from "react"; |
| 2 | +import { useContext } from "react"; |
| 3 | +import { i18nContext } from "../../utils/i18nContext"; |
| 4 | +import { Notifications } from "../../utils/types"; |
| 5 | +import { useMutation } from "@apollo/client"; |
| 6 | +import { UPDATE_NOTIFICATION_CHECK } from "../../graphql/mutations/notifications"; |
| 7 | +// import { } from "../../generated/graphql"; |
| 8 | + |
| 9 | +const NotificationsPanel = ({ |
| 10 | + notification, |
| 11 | +}: { |
| 12 | + notification: Notifications; |
| 13 | +}) => { |
| 14 | + /* |
| 15 | + * STATES |
| 16 | + */ |
| 17 | + const { t } = useContext(i18nContext); |
| 18 | + const notificationTrad = { |
| 19 | + adminMail: notification.admin_email, |
| 20 | + skillName: notification.skill?.name, |
| 21 | + }; |
| 22 | + |
| 23 | + /* |
| 24 | + * MUTATIONS |
| 25 | + */ |
| 26 | + const [updateNotificationCheck] = useMutation(UPDATE_NOTIFICATION_CHECK, { |
| 27 | + variables: { |
| 28 | + id: notification.id, |
| 29 | + }, |
| 30 | + }); |
| 31 | + console.log("coucou"); |
| 32 | + |
| 33 | + useEffect(() => { |
| 34 | + updateNotificationCheck(); |
| 35 | + }, []); |
| 36 | + |
| 37 | + return ( |
| 38 | + <div |
| 39 | + className={`flex relative flex-row bg-light-light dark:bg-dark-light px-4 py-4 mx-2 my-1 rounded-lg border border-light-light dark:border-dark-light`} |
| 40 | + > |
| 41 | + {notification.checked === false && ( |
| 42 | + <div className="absolute top-0 right-0 inline-flex justify-center items-center w-15 h-15 text-xs font-bold text-light-ultrawhite bg-dark-red rounded-full dark:border-gray-900"> |
| 43 | + {t("notification.new")} |
| 44 | + </div> |
| 45 | + )} |
| 46 | + <div className="flex flex-col"> |
| 47 | + <h1 className="font-bold font text-xl"> |
| 48 | + {t("notification.notificationTypeAccepted")} |
| 49 | + </h1> |
| 50 | + |
| 51 | + <div className="flex flex-row w-full"> |
| 52 | + <p className="text-xl"> |
| 53 | + {t("notification.notificationText").replace( |
| 54 | + /adminMail|skillName/gi, |
| 55 | + (matched) => notificationTrad[matched] |
| 56 | + )} |
| 57 | + </p> |
| 58 | + </div> |
| 59 | + |
| 60 | + <p className="opacity-50">{notification.created_at}</p> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + ); |
| 64 | +}; |
| 65 | + |
| 66 | +export default NotificationsPanel; |
0 commit comments