-
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 #78 from CassandraGoose/62-accept-new-pathway
setup allow user to accept new pathway
- Loading branch information
Showing
13 changed files
with
592 additions
and
159 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,22 @@ | ||
'use server'; | ||
import { | ||
addPathwayToUser | ||
} from '@/app/lib/queries'; | ||
import { checkUser } from '@/app/actions/actions'; | ||
import { Pathway } from '../lib/interface'; | ||
|
||
interface Message { | ||
id?: string | number; | ||
error?: string; | ||
} | ||
export async function connectPathway(pathwayId: number): Promise<Message> { | ||
const user = await checkUser(); | ||
|
||
if (!user) { | ||
return { error: 'You must be signed in to complete this action.'}; | ||
} | ||
|
||
const newPathway = await addPathwayToUser(pathwayId) as Pathway; | ||
|
||
return { id: newPathway.id }; | ||
} |
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,46 @@ | ||
'use client'; | ||
import { useState } from 'react'; | ||
import { redirect } from 'next/navigation'; | ||
import { User } from 'lucia'; | ||
import { Pathway } from '@/app/lib/interface'; | ||
import { useFormStatus } from 'react-dom'; | ||
import { connectPathway } from '@/app/actions/pathwayActions'; | ||
|
||
export default function FollowPathwayButton({ | ||
pathway, | ||
hasPathway, | ||
}: { | ||
pathway: Pathway; | ||
hasPathway: boolean; | ||
}) { | ||
const { pending } = useFormStatus(); | ||
const [errorMessage, setErrorMessage] = useState<string>(''); | ||
|
||
return !hasPathway && ( | ||
<form | ||
action={async () => { | ||
const message = await connectPathway(pathway.id); | ||
if (message.error) { | ||
setErrorMessage(message.error); | ||
} else { | ||
return redirect(`/dashboard/${message.id}`); | ||
} | ||
}} | ||
> | ||
<button | ||
className="btn btn-secondary text-bright" | ||
type="submit" | ||
aria-disabled={pending} | ||
> | ||
{pending ? ( | ||
<span className="loading loading-spinner loading-sm bg-loading"></span> | ||
) : ( | ||
'Follow This Pathway' | ||
)} | ||
</button> | ||
<div className="label"> | ||
<span className="label-text-alt text-error">{errorMessage}</span> | ||
</div> | ||
</form> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.