-
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 #274 from colonial-heritage/communityDescription
Community description
- Loading branch information
Showing
10 changed files
with
402 additions
and
145 deletions.
There are no files selected for viewing
36 changes: 33 additions & 3 deletions
36
apps/researcher/src/app/[locale]/communities/[slug]/actions.ts
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,6 +1,36 @@ | ||
'use server'; | ||
|
||
import {joinCommunity} from '@/lib/community'; | ||
import {joinCommunity, updateDescription} from '@/lib/community'; | ||
import {revalidatePath} from 'next/cache'; | ||
|
||
// Export as server actions. | ||
export {joinCommunity}; | ||
interface UpdateDescriptionAndRevalidateProps { | ||
communityId: string; | ||
communitySlug: string; | ||
description: string; | ||
} | ||
|
||
export async function updateDescriptionAndRevalidate({ | ||
communityId, | ||
communitySlug, | ||
description, | ||
}: UpdateDescriptionAndRevalidateProps) { | ||
await updateDescription({communityId, description}); | ||
revalidatePath(`/[locale]/communities/${communitySlug}`, 'page'); | ||
revalidatePath('/[locale]/communities', 'page'); | ||
} | ||
|
||
interface JoinCommunityAndRevalidateProps { | ||
communityId: string; | ||
communitySlug: string; | ||
userId: string; | ||
} | ||
|
||
export async function joinCommunityAndRevalidate({ | ||
communityId, | ||
communitySlug, | ||
userId, | ||
}: JoinCommunityAndRevalidateProps) { | ||
await joinCommunity({communityId, userId}); | ||
revalidatePath(`/[locale]/communities/${communitySlug}`, 'page'); | ||
revalidatePath('/[locale]/communities', 'page'); | ||
} |
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
112 changes: 112 additions & 0 deletions
112
apps/researcher/src/app/[locale]/communities/[slug]/edit-description-form.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,112 @@ | ||
'use client'; | ||
|
||
import {useForm, SubmitHandler} from 'react-hook-form'; | ||
import {useTranslations} from 'next-intl'; | ||
import {useSlideOut, useNotifications} from 'ui'; | ||
import {updateDescriptionAndRevalidate} from './actions'; | ||
|
||
interface Props { | ||
communityId: string; | ||
communitySlug: string; | ||
slideOutId: string; | ||
description?: string; | ||
} | ||
|
||
interface FormValues { | ||
description: string; | ||
communityId: string; | ||
communitySlug: string; | ||
} | ||
|
||
export default function EditDescriptionForm({ | ||
slideOutId, | ||
communityId, | ||
communitySlug, | ||
description, | ||
}: Props) { | ||
const { | ||
register, | ||
handleSubmit, | ||
setError, | ||
formState: {errors, isSubmitting}, | ||
} = useForm({ | ||
defaultValues: { | ||
description: description ?? '', | ||
communityId, | ||
communitySlug, | ||
}, | ||
}); | ||
|
||
const t = useTranslations('Community'); | ||
const {setIsVisible} = useSlideOut(); | ||
const {addNotification} = useNotifications(); | ||
|
||
const onSubmit: SubmitHandler<FormValues> = async descriptionFormValues => { | ||
try { | ||
await updateDescriptionAndRevalidate(descriptionFormValues); | ||
addNotification({ | ||
id: 'add-object-list-success', | ||
message: <>{t('descriptionUpdated')}</>, | ||
type: 'success', | ||
}); | ||
setIsVisible(slideOutId, false); | ||
} catch (err) { | ||
setError('root.serverError', { | ||
message: t('serverError'), | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit(onSubmit)} | ||
className="flex-col gap-6 flex w-full max-w-3xl" | ||
> | ||
{errors.root?.serverError.message && ( | ||
<div className="rounded-md bg-red-50 p-4 mt-3"> | ||
<div className="ml-3"> | ||
<h3 className="text-sm leading-5 font-medium text-red-800"> | ||
{errors.root.serverError.message} | ||
</h3> | ||
</div> | ||
</div> | ||
)} | ||
<div className="flex flex-col sm:flex-row gap-4 "> | ||
<div className="flex flex-col w-full"> | ||
<label className="flex flex-col text-sm"> | ||
<strong>{t('labelDescription')}</strong> | ||
</label> | ||
<textarea | ||
id="description" | ||
{...register('description', { | ||
maxLength: 2000, | ||
})} | ||
rows={4} | ||
className="border border-greenGrey-200 rounded p-2 w-full" | ||
/> | ||
<p> | ||
{errors.description && t(`description_${errors.description.type}`)} | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div className="flex flex-col lg:flex-row gap-4"> | ||
<div className="w-full lg:w-2/3 flex gap-2"> | ||
<button | ||
disabled={isSubmitting} | ||
type="submit" | ||
className="p-1 sm:py-2 sm:px-3 rounded-full text-xs bg-greenGrey-100 hover:bg-greenGrey-200 transition text-greenGrey-800 flex items-center gap-1" | ||
> | ||
{t('changeDescriptionSaveButton')} | ||
</button> | ||
<button | ||
onClick={() => setIsVisible(slideOutId, false)} | ||
className="p-1 sm:py-2 sm:px-3 rounded-full text-xs border border-greenGrey-300 hover:bg-greenGrey-200 transition text-greenGrey-800 flex items-center gap-1" | ||
> | ||
{t('changeDescriptionCancelButton')} | ||
</button> | ||
</div> | ||
</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 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.
4e069ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
colonial-collections-dataset-browser – ./apps/dataset-browser
datasets.colonialcollections.nl
colonial-collections-dataset-browser-colonial-heritage.vercel.app
colonial-collections-dataset-browser-git-main-colonial-heritage.vercel.app
colonial-collections-dataset-browser.vercel.app
4e069ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
colonial-collections-researcher – ./apps/researcher
colonial-collections-researcher.vercel.app
app.colonialcollections.nl
colonial-collections-researcher-colonial-heritage.vercel.app
colonial-collections-researcher-git-main-colonial-heritage.vercel.app