-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from vevcom/feat/interest-group-pages
Feat/Interest Group Pages
- Loading branch information
Showing
31 changed files
with
448 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
import { Action } from '@/actions/Action' | ||
import { InterestGroups } from '@/services/groups/interestGroups' | ||
|
||
export const createInterestGroupAction = Action(InterestGroups.create) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
import { ActionNoData } from '@/actions/Action' | ||
import { InterestGroups } from '@/services/groups/interestGroups' | ||
|
||
export const destroyInterestGroupAction = ActionNoData(InterestGroups.destroy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
import { ActionNoData } from '@/actions/Action' | ||
import { InterestGroups } from '@/services/groups/interestGroups' | ||
|
||
export const readInterestGroupsAction = ActionNoData(InterestGroups.readAll) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
import { Action } from '@/actions/Action' | ||
import { InterestGroups } from '@/services/groups/interestGroups' | ||
|
||
export const updateInterestGroupAction = Action(InterestGroups.update) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/app/interest-groups/CreateInterestGroupForm.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@use '@/styles/ohma'; | ||
|
||
.CreateInterestGroupForm { | ||
min-width: 50vw; | ||
min-height: 50vh; | ||
display: grid; | ||
place-items: center; | ||
form { | ||
display: grid; | ||
place-items: center; | ||
> * { | ||
width: 200px; | ||
margin: 0; | ||
} | ||
button[type="submit"] { | ||
width: 220px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import styles from './CreateInterestGroupForm.module.scss' | ||
import Form from '@/components/Form/Form' | ||
import { createInterestGroupAction } from '@/actions/groups/interestGroups/create' | ||
import TextInput from '@/components/UI/TextInput' | ||
|
||
export default function CreateInterestGroupForm() { | ||
return ( | ||
<div className={styles.CreateInterestGroupForm}> | ||
<h2>Lag interessegruppe</h2> | ||
<Form | ||
refreshOnSuccess | ||
action={createInterestGroupAction.bind(null, {})} | ||
submitText="Lag interessegruppe" | ||
> | ||
<TextInput name="name" label="Navn" /> | ||
<TextInput name="shortName" label="Kortnavn" /> | ||
</Form> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@use '@/styles/ohma'; | ||
|
||
.interestGroup { | ||
margin-top: 2rem; | ||
border-top: 8px solid ohma.$colors-secondary; | ||
padding-top: 1rem; | ||
position: relative; | ||
h2 { | ||
font-size: ohma.$fonts-xl; | ||
} | ||
.admin { | ||
position: absolute; | ||
top: 1em; | ||
right: 1em; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import styles from './InterestGroup.module.scss' | ||
import Form from '@/components/Form/Form' | ||
import TextInput from '@/components/UI/TextInput' | ||
import ArticleSection from '@/components/Cms/ArticleSection/ArticleSection' | ||
import { DestroyInterestGroupAuther, UpdateInterestGroupAuther } from '@/services/groups/interestGroups/Auther' | ||
import { SettingsHeaderItemPopUp } from '@/components/HeaderItems/HeaderItemPopUp' | ||
import { updateInterestGroupAction } from '@/actions/groups/interestGroups/update' | ||
import { destroyInterestGroupAction } from '@/actions/groups/interestGroups/destroy' | ||
import type { SessionMaybeUser } from '@/auth/Session' | ||
import type { ExpandedInterestGroup } from '@/services/groups/interestGroups/Types' | ||
|
||
type PropTypes = { | ||
interestGroup: ExpandedInterestGroup | ||
session: SessionMaybeUser | ||
} | ||
|
||
export default function InterestGroup({ interestGroup, session }: PropTypes) { | ||
const canUpdate = UpdateInterestGroupAuther.dynamicFields({ groupId: interestGroup.groupId }).auth(session) | ||
const canDestroy = DestroyInterestGroupAuther.dynamicFields({}).auth(session) | ||
|
||
const PopUpKey = `Update interest group ${interestGroup.name}` | ||
|
||
return ( | ||
<div className={styles.interestGroup}> | ||
<h2>{interestGroup.name}</h2> | ||
<div className={styles.admin}> | ||
{ | ||
canUpdate.authorized || canDestroy.authorized ? ( | ||
<SettingsHeaderItemPopUp PopUpKey={PopUpKey}> | ||
{ | ||
canUpdate.authorized && ( | ||
<> | ||
<h2>Update interest group</h2> | ||
<Form | ||
refreshOnSuccess | ||
closePopUpOnSuccess={PopUpKey} | ||
action={updateInterestGroupAction.bind( | ||
null, { id: interestGroup.id } | ||
)} | ||
submitText="Endre" | ||
> | ||
<TextInput | ||
defaultValue={interestGroup.name} | ||
name="name" | ||
label="Navn" | ||
/> | ||
<TextInput | ||
defaultValue={interestGroup.shortName} | ||
name="shortName" | ||
label="Kortnavn" | ||
/> | ||
</Form> | ||
</> | ||
) | ||
} | ||
{ | ||
canDestroy.authorized && ( | ||
<Form | ||
refreshOnSuccess | ||
closePopUpOnSuccess={PopUpKey} | ||
action={destroyInterestGroupAction.bind( | ||
null, { id: interestGroup.id } | ||
)} | ||
submitText="Slett" | ||
submitColor="red" | ||
confirmation={{ | ||
confirm: true, | ||
text: `Er du sikker på at du vil slette ${interestGroup.name}?` | ||
}} | ||
/> | ||
) | ||
} | ||
</SettingsHeaderItemPopUp> | ||
) : <></> | ||
} | ||
</div> | ||
<ArticleSection key={interestGroup.id} articleSection={interestGroup.articleSection} /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import CreateInterestGroupForm from './CreateInterestGroupForm' | ||
import InterestGroup from './InterestGroup' | ||
import { readInterestGroupsAction } from '@/actions/groups/interestGroups/read' | ||
import SpecialCmsParagraph from '@/cms/CmsParagraph/SpecialCmsParagraph' | ||
import PageWrapper from '@/components/PageWrapper/PageWrapper' | ||
import { AddHeaderItemPopUp } from '@/components/HeaderItems/HeaderItemPopUp' | ||
import { CreateInterestGroupAuther } from '@/services/groups/interestGroups/Auther' | ||
|
||
export default async function InterestGroups() { | ||
const { session, ...interestGroupsRes } = await readInterestGroupsAction.bind(null, {})() | ||
if (!interestGroupsRes.success) return <div>Failed to load interest groups</div> //TODO: Change to unwrap | ||
const interestGroups = interestGroupsRes.data | ||
|
||
const canCreate = CreateInterestGroupAuther.dynamicFields({}).auth(session) | ||
|
||
return ( | ||
<PageWrapper title="Interessegrupper" headerItem={ | ||
canCreate.authorized && ( | ||
<AddHeaderItemPopUp PopUpKey="Create interest group"> | ||
<CreateInterestGroupForm /> | ||
</AddHeaderItemPopUp> | ||
) | ||
}> | ||
<SpecialCmsParagraph special="INTEREST_GROUP_GENERAL_INFO" /> | ||
<main> | ||
{ | ||
interestGroups.map(interestGroup => ( | ||
<InterestGroup session={session} key={interestGroup.id} interestGroup={interestGroup} /> | ||
)) | ||
} | ||
</main> | ||
</PageWrapper> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AutherFactory } from './Auther' | ||
import type { Permission } from '@prisma/client' | ||
|
||
export const RequirePermissionOrGroupAdmin = AutherFactory< | ||
{ permission: Permission }, | ||
{ groupId: number }, | ||
'USER_NOT_REQUIERED_FOR_AUTHORIZED' | ||
>(({ session, staticFields, dynamicFields }) => ({ | ||
success: session.permissions.includes(staticFields.permission) || session.memberships.some( | ||
membersip => membersip.groupId === dynamicFields.groupId && membersip.admin && membersip.active | ||
), | ||
session, | ||
})) |
11 changes: 11 additions & 0 deletions
11
src/prisma/prismaservice/cms_paragraphs/interest_groups/general_info.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Har du en interesse du har lyst til å dele med andre? Interessegrupper er noe vi har startet for at det skal være lettere for deg å samle folk rundt en felles interesse. | ||
|
||
**Hva er en interessegruppe?** En interessegruppe er en gruppe med studenter som møtes for å snakke om eller dyrke en interesse. En interessegruppe kan omhandle akkurat det du interesserer deg for som du ønsker å dele med andre. Er det noe du føler mangler av tilbud i studenttilværelsen, er det godt mulig at interessegrupper er noe for deg! | ||
|
||
**Hvordan bli en interessegruppe?** Det er meget lett å bli en interessegruppe, bare send en mail til [email protected] med navn på gruppen, kontaktinformasjon gruppeleder og en kort beskrivelse av hva dere gjør. Hvis dere trenger ekstra utstyr er det mulig å søke støtte fra fondet. | ||
|
||
**Ønsker du å opprette en gruppe?** Send en mail til [email protected], så tar vi kontakt. | ||
|
||
Få støtte! Ønsker din gruppe å søke støtte, send en søknad til [email protected]. For å få penger må gruppen bestå av flere aktive medlemmer i Omega, samt ha klart et budsjett over hva de planlegger å bruke pengene på. Søknaden vil så bli vurdert av fondsstyret. Det er altså ikke en garanti å få penger, men hvis formålet er noe Broedre iitem systre kan nyte godt av lover det godt for søknaden. | ||
|
||
Høres dette vrient ut, så fortvil ikke: Vi er her for å hjelpe dere. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RequirePermission } from '@/auth/auther/RequirePermission' | ||
import { RequirePermissionOrGroupAdmin } from '@/auth/auther/RequirePermissionOrGroupAdmin' | ||
|
||
export const ReadInterestGroupAuther = RequirePermission.staticFields({ permission: 'INTEREST_GROUP_READ' }) | ||
|
||
export const CreateInterestGroupAuther = RequirePermission.staticFields({ permission: 'INTEREST_GROUP_ADMIN' }) | ||
|
||
export const UpdateInterestGroupAuther = RequirePermissionOrGroupAdmin.staticFields({ permission: 'INTEREST_GROUP_ADMIN' }) | ||
|
||
export const DestroyInterestGroupAuther = RequirePermission.staticFields({ permission: 'INTEREST_GROUP_ADMIN' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import type { ExpandedArticleSection } from '@/services/cms/articleSections/Types' | ||
import type { InterestGroup } from '@prisma/client' | ||
|
||
export type ExpandedInterestGroup = InterestGroup | ||
export type ExpandedInterestGroup = InterestGroup & { | ||
articleSection: ExpandedArticleSection | ||
} |
Oops, something went wrong.