-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to joing nominations and edit them
Signed-off-by: miam-miam100 <[email protected]>
- Loading branch information
Showing
9 changed files
with
144 additions
and
3 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
23 changes: 23 additions & 0 deletions
23
src/app/(pages)/nominations/[electionId]/join/[joinKey]/JoinNominationForm/index.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,23 @@ | ||
@import "../../../../../../_css/common"; | ||
|
||
.error { | ||
color: red; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.formWrapper { | ||
width: 66.66%; | ||
|
||
@include mid-break { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.submit { | ||
margin-top: var(--base); | ||
} | ||
|
||
.message { | ||
margin-bottom: var(--base); | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
src/app/(pages)/nominations/[electionId]/join/[joinKey]/JoinNominationForm/index.tsx
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,59 @@ | ||
'use client' | ||
|
||
import React, { Fragment, useCallback, useState } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime' | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/navigation' | ||
|
||
import { Button } from '../../../../../../_components/Button' | ||
import { Input } from '../../../../../../_components/Input' | ||
import { Message } from '../../../../../../_components/Message' | ||
|
||
import classes from './index.module.scss' | ||
|
||
async function joinNomination( | ||
router: AppRouterInstance, | ||
nominationId: string, | ||
joinKey: string, | ||
setError, | ||
) { | ||
try { | ||
const res = await fetch( | ||
`${process.env.NEXT_PUBLIC_SERVER_URL}/api/nominations/${nominationId}/join/${joinKey}`, | ||
{ | ||
method: 'POST', | ||
credentials: 'include', | ||
}, | ||
) | ||
const json = await res.json() | ||
console.log(json) | ||
if (json?.success) { | ||
router.push(`/nominations/${nominationId}`) | ||
} | ||
if (json?.error) { | ||
setError(json.error) | ||
} | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
} | ||
|
||
export const JoinNominationForm: React.FC<{ nominationId?: string; joinKey?: string }> = params => { | ||
const { nominationId, joinKey } = params | ||
const router = useRouter() | ||
const [error, setError] = useState<string>('') | ||
|
||
return ( | ||
<Fragment> | ||
<Button | ||
appearance="primary" | ||
label="Join Nomination" | ||
onClick={async () => { | ||
await joinNomination(router, nominationId, joinKey, setError) | ||
}} | ||
/> | ||
{error && <p>{error}</p>} | ||
</Fragment> | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
src/app/(pages)/nominations/[electionId]/join/[joinKey]/index.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,5 @@ | ||
@import "../../../../../_css/common"; | ||
|
||
.recoverPassword { | ||
margin-bottom: var(--block-padding); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/app/(pages)/nominations/[electionId]/join/[joinKey]/page.tsx
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,32 @@ | ||
import React from 'react' | ||
import { Metadata } from 'next' | ||
|
||
import { Gutter } from '../../../../../_components/Gutter' | ||
import { getMeUser } from '../../../../../_utilities/getMeUser' | ||
import { mergeOpenGraph } from '../../../../../_utilities/mergeOpenGraph' | ||
import { JoinNominationForm } from './JoinNominationForm' | ||
|
||
import classes from './index.module.scss' | ||
|
||
export default async function JoinNomination({ params: { electionId: nominationId, joinKey } }) { | ||
const { user } = await getMeUser({ | ||
nullUserRedirect: `/login?error=${encodeURIComponent( | ||
'You must be logged in to access your account.', | ||
)}&redirect=${encodeURIComponent(`/nominations/${nominationId}/join/${joinKey}`)}`, | ||
}) | ||
|
||
return ( | ||
<Gutter className={classes.recoverPassword}> | ||
<JoinNominationForm nominationId={nominationId} joinKey={joinKey} /> | ||
</Gutter> | ||
) | ||
} | ||
|
||
export const metadata: Metadata = { | ||
title: 'Recover Password', | ||
description: 'Enter your email address to recover your password.', | ||
openGraph: mergeOpenGraph({ | ||
title: 'Recover Password', | ||
url: '/recover-password', | ||
}), | ||
} |
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