Skip to content

Commit

Permalink
Merge branch 'master' into osa-perms-overwrite-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
julianweng authored Nov 1, 2024
2 parents 02439d2 + 63c7a7d commit 8be21ce
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 21 deletions.
51 changes: 50 additions & 1 deletion backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6562,6 +6562,52 @@ def remove_clubs_from_exception(self, *args, **kwargs):
)
return Response([])

@action(detail=True, methods=["GET"])
def club_applications(self, *args, **kwargs):
"""
Retrieve club applications for given cycle
---
requestBody:
content: {}
responses:
"200":
content:
application/json:
schema:
type: array
items:
type: object
properties:
name:
type: string
id:
type: integer
application_end_time:
type: string
format: date-time
application_end_time_exception:
type: string
club__name:
type: string
club__code:
type: string
---
"""
cycle = self.get_object()

return Response(
ClubApplication.objects.filter(application_cycle=cycle)
.select_related("club")
.values(
"name",
"id",
"application_end_time",
"application_end_time_exception",
"club__name",
"club__code",
)
)

@action(detail=True, methods=["GET"])
def applications(self, *args, **kwargs):
"""
Expand All @@ -6570,7 +6616,10 @@ def applications(self, *args, **kwargs):
requestBody: {}
responses:
"200":
content: {}
content:
text/csv:
schema:
type: string
---
"""
cycle = self.get_object()
Expand Down
81 changes: 61 additions & 20 deletions frontend/components/Settings/WhartonApplicationCycles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import ModelForm from '../ModelForm'

const fields = (
<>
<Field name="name" as={TextField} />
<Field name="start_date" as={DateTimeField} />
<Field name="end_date" as={DateTimeField} />
<Field name="release_date" as={DateTimeField} />
<Field name="name" as={TextField} required />
<Field name="start_date" as={DateTimeField} required />
<Field name="end_date" as={DateTimeField} required />
<Field name="release_date" as={DateTimeField} required />
</>
)

type Cycle = {
name: string
id: number | null
endDate: Date
}

type ClubOption = {
Expand All @@ -35,7 +36,8 @@ type ExtensionOption = {
clubName: string
endDate: Date
exception?: boolean
changed: boolean
originalEndDate: Date
originalException: boolean
}

const ScrollWrapper = styled.div`
Expand All @@ -44,17 +46,24 @@ const ScrollWrapper = styled.div`
height: 40vh;
`

type ClubApplicationWithClub = ClubApplication & {
club__name: string
club__code: number
}

const WhartonApplicationCycles = (): ReactElement => {
const [editMembership, setEditMembership] = useState(false)
const [membershipCycle, setMembershipCycle] = useState<Cycle>({
name: '',
id: null,
endDate: new Date(),
})

const [editExtensions, setEditExtensions] = useState(false)
const [extensionsCycle, setExtensionsCycle] = useState<Cycle>({
name: '',
id: null,
endDate: new Date(),
})

const [clubsSelectedMembership, setClubsSelectedMembership] = useState<
Expand All @@ -81,7 +90,10 @@ const WhartonApplicationCycles = (): ReactElement => {
const closeExtensionsModal = (): void => {
setEditExtensions(false)
// calculate clubs that have changed
const clubsToUpdate = clubsExtensions.filter((x) => x.changed)
const clubsToUpdate = clubsExtensions.filter(
(x) =>
x.originalEndDate !== x.endDate || x.originalException !== x.exception,
)
// split into clubs with exceptions and clubs without
const clubsExceptions = clubsToUpdate.filter((x) => x.exception)
const clubsNoExceptions = clubsToUpdate.filter((x) => !x.exception)
Expand Down Expand Up @@ -147,18 +159,23 @@ const WhartonApplicationCycles = (): ReactElement => {

useEffect(() => {
if (extensionsCycle && extensionsCycle.id != null) {
doApiRequest(`/cycles/${extensionsCycle.id}/clubs?format=json`)
doApiRequest(
`/cycles/${extensionsCycle.id}/club_applications?format=json`,
)
.then((resp) => resp.json())
.then((data) => {
const initialOptions = data.map((club: ClubApplication) => {
return {
id: club.id,
clubName: club.name,
endDate: new Date(club.application_end_time),
exception: club.application_end_time_exception,
changed: false,
}
})
const initialOptions = data.map(
(application: ClubApplicationWithClub) => {
return {
id: application.id,
clubName: application.club__name,
endDate: new Date(application.application_end_time),
exception: application.application_end_time_exception,
originalEndDate: new Date(application.application_end_time),
originalException: application.application_end_time_exception,
}
},
)
setClubsExtensions(initialOptions)
})
}
Expand Down Expand Up @@ -190,7 +207,11 @@ const WhartonApplicationCycles = (): ReactElement => {
<button
className="button is-info is-small"
onClick={() => {
setMembershipCycle({ name: object.name, id: object.id })
setMembershipCycle({
name: object.name,
id: object.id,
endDate: new Date(object.end_date),
})
setEditMembership(true)
setEditExtensions(false)
}}
Expand All @@ -200,7 +221,11 @@ const WhartonApplicationCycles = (): ReactElement => {
<button
className="button is-info is-small"
onClick={() => {
setExtensionsCycle({ name: object.name, id: object.id })
setExtensionsCycle({
name: object.name,
id: object.id,
endDate: new Date(object.end_date),
})
setEditExtensions(true)
setEditMembership(false)
}}
Expand Down Expand Up @@ -290,7 +315,6 @@ const WhartonApplicationCycles = (): ReactElement => {
selected={club.endDate}
onChange={(date) => {
club.endDate = date
club.changed = true
setClubsExtensions([...clubsExtensions])
}}
/>
Expand All @@ -299,7 +323,6 @@ const WhartonApplicationCycles = (): ReactElement => {
<Checkbox
onChange={(e) => {
club.exception = e.target.checked
club.changed = true
setClubsExtensions([...clubsExtensions])
}}
checked={
Expand All @@ -320,9 +343,27 @@ const WhartonApplicationCycles = (): ReactElement => {
className="button is-primary"
style={{ position: 'absolute', bottom: 10, right: 10 }}
onClick={closeExtensionsModal}
disabled={clubsExtensions.some(
(x) =>
// For the case where we change end date without giving an exception to a club without one
!x.exception &&
!x.originalException &&
x.endDate.getTime() !== extensionsCycle.endDate.getTime(),
)}
>
Submit
</button>
{clubsExtensions.some(
(x) =>
!x.exception &&
!x.originalException &&
x.endDate.getTime() !== extensionsCycle.endDate.getTime(),
) && (
<p className="is-danger">
To change the end date for a club, you must also check its
exception box.
</p>
)}
</>
)}
</Modal>
Expand Down

0 comments on commit 8be21ce

Please sign in to comment.