Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin note frontend #498

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/components/ClubCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CardWrapper = styled.div`
}
`

const Description = styled.p`
export const Description = styled.p`
margin-top: 0.2rem;
color: ${CLUBS_GREY_LIGHT};
width: 100%;
Expand Down
10 changes: 10 additions & 0 deletions frontend/components/ClubEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRouter } from 'next/router'
import React, { ReactElement, useEffect, useState } from 'react'
import { toast, TypeOptions } from 'react-toastify'

import AdminNotesPage from '../components/ClubEditPage/AdminNotesPage'
import ApplicationsPage from '../components/ClubEditPage/ApplicationsPage'
import ClubEditCard from '../components/ClubEditPage/ClubEditCard'
import ClubManagementCard from '../components/ClubEditPage/ClubManagementCard'
Expand All @@ -25,6 +26,7 @@ import {
School,
StudentType,
Tag,
UserInfo,
VisitType,
Year,
} from '../types'
Expand Down Expand Up @@ -73,6 +75,7 @@ type ClubFormProps = {
tags: Tag[]
studentTypes: StudentType[]
tab?: string | null
userInfo: UserInfo
}

const ClubForm = ({
Expand All @@ -83,6 +86,7 @@ const ClubForm = ({
tags,
studentTypes,
clubId,
userInfo,
tab,
}: ClubFormProps): ReactElement => {
const [club, setClub] = useState<Club | null>(null)
Expand Down Expand Up @@ -369,6 +373,12 @@ const ClubForm = ({
),
disabled: !SHOW_ORG_MANAGEMENT,
},
{
name: 'note',
label: 'Notes',
content: <AdminNotesPage club={club} />,
disabled: !userInfo.is_superuser,
},
]
}

Expand Down
67 changes: 67 additions & 0 deletions frontend/components/ClubEditPage/AdminNotesCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { ReactElement } from 'react'
import styled from 'styled-components'

import { CardTitle, Description } from '../ClubCard'
import { Card } from '../common'

const NotesCard = styled(Card)`
border: 1.5px solid gray;
cursor: pointer;
margin: 16px 0px;
`
const OverflowWrapper = styled.div`
width: 100%;
display: table;
table-layout: fixed;
`
const OverflowDescription = styled(Description)`
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
word-break: break-all;
word-wrap: break-word;
`
const NoteInfo = styled.div`
display: flex;
justify-content: space-between;
font-size: 0.75rem;
opacity: 0.75;
user-select: none;
`

function extractContentFromHtml(html) {
return new DOMParser().parseFromString(html, 'text/html').documentElement
.textContent
}

export default function AdminNotesCard({
note,
viewNote,
disabled,
}): ReactElement {
return (
<NotesCard
hoverable
onClick={
disabled
? () => {
// pass
}
: () => viewNote(note)
}
disabled={disabled}
>
<CardTitle>{note.title}</CardTitle>
<OverflowWrapper>
<OverflowDescription>
{extractContentFromHtml(note.content)}
</OverflowDescription>
</OverflowWrapper>

<NoteInfo>
<b>{note.creator}</b>
<p>{new Date(note.created_at).toLocaleDateString()}</p>
</NoteInfo>
</NotesCard>
)
}
Loading