|
| 1 | +import CardLink from 'src/components/CardLink' |
| 2 | +import CardItemWithActions from 'src/components/CardItemWithActions' |
| 3 | +import { Attributes } from 'src/lib/analytics' |
| 4 | +import { ConferenceItemPropsType } from 'src/types' |
| 5 | +import { MdAccessTime } from 'react-icons/md' |
| 6 | +import ColoredLanguagesBadge from 'src/components/ColoredLanguagesBadge' |
| 7 | +import { flag } from 'country-emoji' |
| 8 | +import { IoIosPin } from 'react-icons/io' |
| 9 | +import { RiCalendarEventFill } from 'react-icons/ri' |
| 10 | + |
| 11 | +const ConferencesItem = (props: ConferenceItemPropsType) => { |
| 12 | + const { item, index, listingMode } = props |
| 13 | + |
| 14 | + const ConferenceLocation = () => { |
| 15 | + if (item.online) { |
| 16 | + return '🌐 Online' |
| 17 | + } |
| 18 | + if (item.country) { |
| 19 | + return `${flag(item.country.replace(/[^a-zA-Z ]/g, ''))} ${item.city}` |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + const ConferenceDate = () => { |
| 24 | + if (!item.start_date) { |
| 25 | + return '' |
| 26 | + } |
| 27 | + const monthNames = [ |
| 28 | + 'January', |
| 29 | + 'February', |
| 30 | + 'March', |
| 31 | + 'April', |
| 32 | + 'May', |
| 33 | + 'June', |
| 34 | + 'July', |
| 35 | + 'August', |
| 36 | + 'September', |
| 37 | + 'October', |
| 38 | + 'November', |
| 39 | + 'December', |
| 40 | + ] |
| 41 | + const startDate = new Date(item.start_date) |
| 42 | + const startMnth = monthNames[startDate.getMonth()] |
| 43 | + let value = `${startMnth} ${('0' + startDate.getDate()).slice(-2)}` |
| 44 | + if (!item.end_date || item.end_date === item.start_date) { |
| 45 | + return value |
| 46 | + } |
| 47 | + const endDate = new Date(item.end_date) |
| 48 | + let endValue = ('0' + endDate.getDate()).slice(-2) |
| 49 | + if (endDate.getMonth() !== startDate.getMonth()) { |
| 50 | + endValue = `${monthNames[endDate.getMonth()]} ${endValue}` |
| 51 | + } |
| 52 | + return `${value} - ${endValue}` |
| 53 | + } |
| 54 | + return ( |
| 55 | + <CardItemWithActions |
| 56 | + source={'conferences'} |
| 57 | + index={index} |
| 58 | + key={index} |
| 59 | + item={{ ...item, title: item.name }} |
| 60 | + cardItem={ |
| 61 | + <> |
| 62 | + <CardLink |
| 63 | + link={item.url} |
| 64 | + analyticsAttributes={{ |
| 65 | + [Attributes.TRIGERED_FROM]: 'card', |
| 66 | + [Attributes.TITLE]: item.name, |
| 67 | + [Attributes.LINK]: item.url, |
| 68 | + [Attributes.SOURCE]: 'conferences', |
| 69 | + }}> |
| 70 | + <RiCalendarEventFill className={'rowTitleIcon'} /> |
| 71 | + {item.name} |
| 72 | + </CardLink> |
| 73 | + {listingMode === 'normal' ? ( |
| 74 | + <> |
| 75 | + <div className="rowDescription"> |
| 76 | + <span className="rowItem"> |
| 77 | + <IoIosPin className="rowItemIcon" /> {ConferenceLocation()} |
| 78 | + </span> |
| 79 | + <span className="rowItem"> |
| 80 | + <MdAccessTime className="rowItemIcon" /> {ConferenceDate()} |
| 81 | + </span> |
| 82 | + </div> |
| 83 | + <div className="rowDetails"> |
| 84 | + <ColoredLanguagesBadge languages={[item.tag]} /> |
| 85 | + </div> |
| 86 | + </> |
| 87 | + ) : ( |
| 88 | + <div className="rowDescription"> |
| 89 | + <span className="rowItem"> |
| 90 | + <MdAccessTime className="rowItemIcon" /> {ConferenceDate()} |
| 91 | + </span> |
| 92 | + </div> |
| 93 | + )} |
| 94 | + </> |
| 95 | + } |
| 96 | + /> |
| 97 | + ) |
| 98 | +} |
| 99 | + |
| 100 | +export default ConferencesItem |
0 commit comments