Skip to content

Commit d1c24a0

Browse files
authored
Merge pull request #241 from ln-dev7/feat/add-collaborators-on-form
Feat/add collaborators on form
2 parents 2188464 + 0ef054a commit d1c24a0

13 files changed

Lines changed: 346 additions & 150 deletions

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @ln-dev7/sharuco
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Thanks [@ln-dev7](https://github.com/ln-dev7)!
8+
9+
**Full Changelog**: https://github.com/ln-dev7/sharuco/compare/v1.0.0...v1.0.1
10+
311
## 1.0.0
412

513
### Major Changes

components/avatar-user.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export function AvatarUser() {
5050
<SheetTrigger asChild>
5151
<div className="relative">
5252
{data && data.exists && data.data.premium && (
53-
<div className="absolute z-10 rounded-full -bottom-1 -right-1 flex items-center justify-center border-2 border-yellow-500 bg-white dark:bg-slate-800">
54-
<Verified className="shrink-0 h-5 w-5 text-yellow-500 p-1" />
53+
<div className="absolute -bottom-1 -right-1 z-10 flex items-center justify-center rounded-full border-2 border-yellow-500 bg-white dark:bg-slate-800">
54+
<Verified className="h-5 w-5 shrink-0 p-1 text-yellow-500" />
5555
</div>
5656
)}
5757
<Avatar

components/form/publish.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,26 @@ export default function PublishForms({ dataForm }: { dataForm: any }) {
160160
<Eye className="mr-2 h-4 w-4" />
161161
View form
162162
</Link>
163-
<h3 className="text-md mt-4 font-semibold">
164-
{dataForm.published
165-
? "Your form is currently online and can be viewed and answered by anyone at the link"
166-
: "Your form is not published so can only be seen by you alone"}
167-
</h3>
168-
{isLoadingUpdateForm ? (
169-
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
170-
) : (
171-
<p
172-
className="mb-4 mt-2 cursor-pointer text-sm font-semibold uppercase text-muted-foreground underline underline-offset-4"
173-
onClick={() => changeStatutOfForm()}
174-
>
175-
{!dataForm?.published ? "Publish" : "Unpublish"} your form
176-
</p>
163+
{dataForm.idAuthor === userPseudo && (
164+
<>
165+
<h3 className="text-md mt-4 font-semibold">
166+
{dataForm.published
167+
? "Your form is currently online and can be viewed and answered by anyone at the link"
168+
: "Your form is not published so can only be seen by you alone"}
169+
</h3>
170+
<>
171+
{isLoadingUpdateForm ? (
172+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
173+
) : (
174+
<p
175+
className="mb-4 mt-2 cursor-pointer text-sm font-semibold uppercase text-muted-foreground underline underline-offset-4"
176+
onClick={() => changeStatutOfForm()}
177+
>
178+
{!dataForm?.published ? "Publish" : "Unpublish"} your form
179+
</p>
180+
)}
181+
</>
182+
</>
177183
)}
178184
{isSuccessUpdateForm && (
179185
<div

components/form/questions.tsx

Lines changed: 103 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export default function QuestionsForms({ dataForm }: { dataForm: any }) {
121121
updateFormDocument,
122122
isLoading: isLoadingUpdateForm,
123123
isError: isErrorUpdateForm,
124+
error: errorUpdateForm,
124125
isSuccess: isSuccessUpdateForm,
125126
reset: resetUpdateForm,
126127
}: any = useUpdateFormDocument("forms")
@@ -213,79 +214,85 @@ export default function QuestionsForms({ dataForm }: { dataForm: any }) {
213214

214215
return (
215216
<div className="flex w-full flex-col items-start gap-4 sm:flex-row">
216-
<div className="flex w-full shrink-0 flex-col items-start gap-2 rounded-md sm:sticky sm:top-20 sm:w-[250px]">
217-
<button
218-
onClick={() => handleAddField("heading")}
219-
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
220-
>
221-
<Heading className="h-5 w-5" />
222-
<span className="ml-2 text-sm font-semibold">Heading</span>
223-
</button>
224-
<button
225-
onClick={() => handleAddField("text")}
226-
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
227-
>
228-
<Minus className="h-5 w-5" />
229-
<span className="ml-2 text-sm font-semibold">Short answer</span>
230-
</button>
231-
<button
232-
onClick={() => handleAddField("longtext")}
233-
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
234-
>
235-
<AlignJustify className="h-5 w-5" />
236-
<span className="ml-2 text-sm font-semibold">Long answer</span>
237-
</button>
238-
<button
239-
//onClick={() => handleAddField("link")}
240-
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
241-
>
242-
<LinkIcon className="h-5 w-5" />
243-
<span className="ml-2 text-sm font-semibold">Link</span>
244-
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
245-
soon
246-
</span>
247-
</button>
248-
<button
249-
//onClick={() => handleAddField("email")}
250-
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
251-
>
252-
<Mail className="h-5 w-5" />
253-
<span className="ml-2 text-sm font-semibold">E-mail</span>
254-
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
255-
soon
256-
</span>
257-
</button>
258-
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
259-
<CircleDot className="h-5 w-5" />
260-
<span className="ml-2 text-sm font-semibold">Unique choice</span>
261-
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
262-
soon
263-
</span>
264-
</button>
265-
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
266-
<ListChecks className="h-5 w-5" />
267-
<span className="ml-2 text-sm font-semibold">Multi choice</span>
268-
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
269-
soon
270-
</span>
271-
</button>
272-
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
273-
<List className="h-5 w-5" />
274-
<span className="ml-2 text-sm font-semibold">List of choices</span>
275-
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
276-
soon
277-
</span>
278-
</button>
279-
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
280-
<Calendar className="h-5 w-5" />
281-
<span className="ml-2 text-sm font-semibold">Date</span>
282-
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
283-
soon
284-
</span>
285-
</button>
286-
<Separator className="my-2 hidden w-full sm:block" />
287-
</div>
288-
<Separator className="my-2 block w-full sm:hidden" />
217+
{dataForm.idAuthor === userPseudo && (
218+
<>
219+
<div className="flex w-full shrink-0 flex-col items-start gap-2 rounded-md sm:sticky sm:top-20 sm:w-[250px]">
220+
<button
221+
onClick={() => handleAddField("heading")}
222+
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
223+
>
224+
<Heading className="h-5 w-5" />
225+
<span className="ml-2 text-sm font-semibold">Heading</span>
226+
</button>
227+
<button
228+
onClick={() => handleAddField("text")}
229+
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
230+
>
231+
<Minus className="h-5 w-5" />
232+
<span className="ml-2 text-sm font-semibold">Short answer</span>
233+
</button>
234+
<button
235+
onClick={() => handleAddField("longtext")}
236+
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
237+
>
238+
<AlignJustify className="h-5 w-5" />
239+
<span className="ml-2 text-sm font-semibold">Long answer</span>
240+
</button>
241+
<button
242+
//onClick={() => handleAddField("link")}
243+
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
244+
>
245+
<LinkIcon className="h-5 w-5" />
246+
<span className="ml-2 text-sm font-semibold">Link</span>
247+
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
248+
soon
249+
</span>
250+
</button>
251+
<button
252+
//onClick={() => handleAddField("email")}
253+
className="flex w-full items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800"
254+
>
255+
<Mail className="h-5 w-5" />
256+
<span className="ml-2 text-sm font-semibold">E-mail</span>
257+
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
258+
soon
259+
</span>
260+
</button>
261+
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
262+
<CircleDot className="h-5 w-5" />
263+
<span className="ml-2 text-sm font-semibold">Unique choice</span>
264+
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
265+
soon
266+
</span>
267+
</button>
268+
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
269+
<ListChecks className="h-5 w-5" />
270+
<span className="ml-2 text-sm font-semibold">Multi choice</span>
271+
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
272+
soon
273+
</span>
274+
</button>
275+
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
276+
<List className="h-5 w-5" />
277+
<span className="ml-2 text-sm font-semibold">
278+
List of choices
279+
</span>
280+
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
281+
soon
282+
</span>
283+
</button>
284+
<button className="flex w-full cursor-default items-center justify-start gap-1 rounded-md px-4 py-2 hover:bg-slate-100 hover:dark:bg-slate-800">
285+
<Calendar className="h-5 w-5" />
286+
<span className="ml-2 text-sm font-semibold">Date</span>
287+
<span className="mr-2 rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
288+
soon
289+
</span>
290+
</button>
291+
<Separator className="my-2 hidden w-full sm:block" />
292+
</div>
293+
<Separator className="my-2 block w-full sm:hidden" />
294+
</>
295+
)}
289296
<div
290297
id="questions"
291298
className="relative flex w-full flex-col items-start gap-4 overflow-hidden rounded-md border px-4 pb-4 pt-7"
@@ -350,13 +357,15 @@ export default function QuestionsForms({ dataForm }: { dataForm: any }) {
350357
{/* {errors?.questions?.[index]?.text && (
351358
<p>{errors.questions[index].text.message}</p>
352359
)} */}
353-
<Button
354-
variant="destructive"
355-
className="absolute -top-2 right-2 flex h-10 w-10 items-center justify-center rounded-full p-2"
356-
onClick={() => handleRemoveField(index)}
357-
>
358-
<Trash className="h-4 w-4" />
359-
</Button>
360+
{dataForm.idAuthor === userPseudo && (
361+
<Button
362+
variant="destructive"
363+
className="absolute -top-2 right-2 flex h-10 w-10 items-center justify-center rounded-full p-2"
364+
onClick={() => handleRemoveField(index)}
365+
>
366+
<Trash className="h-4 w-4" />
367+
</Button>
368+
)}
360369
</div>
361370
)
362371
})}
@@ -390,18 +399,20 @@ export default function QuestionsForms({ dataForm }: { dataForm: any }) {
390399
</button>
391400
</div>
392401
)}
393-
<Button
394-
variant="outline"
395-
disabled={isLoadingUpdateForm}
396-
onClick={isLoadingUpdateForm ? undefined : handleSubmit(onSubmit)}
397-
>
398-
{isLoadingUpdateForm ? (
399-
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
400-
) : (
401-
<Save className="mr-2 h-4 w-4" />
402-
)}
403-
Save questions
404-
</Button>
402+
{dataForm.idAuthor === userPseudo && (
403+
<Button
404+
variant="outline"
405+
disabled={isLoadingUpdateForm}
406+
onClick={isLoadingUpdateForm ? undefined : handleSubmit(onSubmit)}
407+
>
408+
{isLoadingUpdateForm ? (
409+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
410+
) : (
411+
<Save className="mr-2 h-4 w-4" />
412+
)}
413+
Save questions
414+
</Button>
415+
)}
405416
</div>
406417
</div>
407418
)

components/form/responses.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export default function ResponsesForms({ dataForm }: { dataForm: any }) {
243243
? "border-2 border-solid border-emerald-500 dark:border-emerald-900"
244244
: ""
245245
)}
246-
key={index}
246+
key={response.idResponse}
247247
>
248248
<Accordion
249249
type="single"

0 commit comments

Comments
 (0)