import { assertUnreachable } from "~/utils/types"; import { badgePage, PLUS_VOTING_PAGE, plusSuggestionPage, SENDOUQ_PAGE, scrimPage, scrimsPage, sendouQMatchPage, tournamentBracketsPage, tournamentRegisterPage, tournamentTeamPage, userArtPage, userEditProfilePage, } from "~/utils/urls"; import type { Notification } from "./notifications-types"; export const notificationNavIcon = (type: Notification["type"]) => { switch (type) { case "BADGE_ADDED": case "BADGE_MANAGER_ADDED": return "badges"; case "PLUS_SUGGESTION_ADDED": case "PLUS_VOTING_STARTED": return "plus"; case "SQ_ADDED_TO_GROUP": case "SQ_NEW_MATCH": case "SEASON_STARTED": return "sendouq"; case "TAGGED_TO_ART": case "COMMISSIONS_CLOSED": return "art"; case "TO_ADDED_TO_TEAM": case "TO_BRACKET_STARTED": case "TO_CHECK_IN_OPENED": case "TO_TEST_CREATED": return "medal"; case "SCRIM_NEW_REQUEST": case "SCRIM_SCHEDULED": case "SCRIM_CANCELED": case "SCRIM_STARTING_SOON": return "scrims"; default: assertUnreachable(type); } }; export const notificationLink = (notification: Notification) => { switch (notification.type) { case "BADGE_ADDED": return badgePage(notification.meta.badgeId); case "BADGE_MANAGER_ADDED": return badgePage(notification.meta.badgeId); case "PLUS_SUGGESTION_ADDED": return plusSuggestionPage({ tier: notification.meta.tier }); case "PLUS_VOTING_STARTED": return PLUS_VOTING_PAGE; case "SEASON_STARTED": case "SQ_ADDED_TO_GROUP": return SENDOUQ_PAGE; case "SQ_NEW_MATCH": return sendouQMatchPage(notification.meta.matchId); case "TAGGED_TO_ART": return userArtPage( { discordId: notification.meta.adderDiscordId }, "MADE-BY", notification.meta.artId, ); case "TO_ADDED_TO_TEAM": return tournamentTeamPage({ tournamentId: notification.meta.tournamentId, tournamentTeamId: notification.meta.tournamentTeamId, }); case "TO_BRACKET_STARTED": return tournamentBracketsPage({ tournamentId: notification.meta.tournamentId, bracketIdx: notification.meta.bracketIdx, }); case "TO_TEST_CREATED": case "TO_CHECK_IN_OPENED": return tournamentRegisterPage(notification.meta.tournamentId); case "SCRIM_NEW_REQUEST": { return scrimsPage(); } case "SCRIM_CANCELED": case "SCRIM_SCHEDULED": case "SCRIM_STARTING_SOON": { return scrimPage(notification.meta.id); } case "COMMISSIONS_CLOSED": { return userEditProfilePage({ discordId: notification.meta.discordId }); } default: assertUnreachable(notification); } }; /** Takes the `meta` object of a notification and transforms it (if needed) to show the translated string to user */ export const mapMetaForTranslation = ( notification: Notification, language: string, ) => { if ( notification.type === "SCRIM_SCHEDULED" || notification.type === "SCRIM_CANCELED" || notification.type === "SCRIM_STARTING_SOON" ) { return { ...notification.meta, timeString: new Date(notification.meta.at).toLocaleString(language, { day: "numeric", month: "numeric", hour: "numeric", minute: "numeric", }), }; } return notification.meta; };