Skip to content

Commit 2d30f8e

Browse files
committed
Interfaces visible to collaborators
1 parent 7f12cb6 commit 2d30f8e

8 files changed

Lines changed: 203 additions & 157 deletions

File tree

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/settings.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,11 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
394394
<div className="flex w-full flex-col items-start gap-1">
395395
<Label className="text-left">Add people to manage this form.</Label>
396396
<p className="text-left text-sm">
397-
The people you have added will be able to modify and view the
398-
answers to this form.
397+
The added persons will be able to consult the answers to your
398+
form.
399399
</p>
400400
</div>
401-
<div className="w-full flex items-center gap-2 mb-2">
401+
<div className="mb-2 flex w-full items-center gap-2">
402402
<Input
403403
placeholder="Enter username"
404404
onChange={(e) => {
@@ -425,22 +425,22 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
425425
</Button>
426426
</div>
427427
{dataForm.collaborators.length !== 0 && (
428-
<div className="w-full flex flex-col gap-2">
428+
<div className="flex w-full flex-col gap-2">
429429
{dataForm.collaborators.map((collaborator, index) => (
430430
<div
431431
key={collaborator.pseudo}
432-
className="w-full flex items-center bg-slate-50 dark:bg-slate-800 py-3 px-5 rounded-md"
432+
className="flex w-full items-center rounded-md bg-slate-50 px-5 py-3 dark:bg-slate-800"
433433
>
434-
<div className="w-full flex">
434+
<div className="flex w-full">
435435
<a
436436
href={`/user/${collaborator.pseudo}`}
437-
className="text-sm font-semibold underline underline-offset-4 cursor-pointer"
437+
className="cursor-pointer text-sm font-semibold underline underline-offset-4"
438438
>
439439
{collaborator.pseudo}
440440
</a>
441441
</div>
442442
<span
443-
className="shrink-0 block text-sm text-red-600 font-medium underline underline-offset-4 cursor-pointer"
443+
className="block shrink-0 cursor-pointer text-sm font-medium text-red-600 underline underline-offset-4"
444444
onClick={() => {
445445
isLoadingUpdateForm
446446
? undefined
@@ -534,8 +534,8 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
534534
</Label>
535535
</div> */}
536536

537-
<div className="sticky inset-x-0 bottom-0 flex w-full border-t flex-col items-start gap-2 bg-white py-4 dark:bg-slate-900">
538-
<div className="w-full flex items-center justify-between">
537+
<div className="sticky inset-x-0 bottom-0 flex w-full flex-col items-start gap-2 border-t bg-white py-4 dark:bg-slate-900">
538+
<div className="flex w-full items-center justify-between">
539539
<Button
540540
variant="default"
541541
disabled={isLoadingUpdateForm || checkIfUsernameExist}
@@ -562,7 +562,7 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
562562
</AlertDialogTitle>
563563
<AlertDialogDescription className="space-y-3">
564564
<div
565-
className="rounded-lg bg-red-50 p-4 text-sm text-red-800 dark:bg-gray-800 dark:text-red-400 font-semibold"
565+
className="rounded-lg bg-red-50 p-4 text-sm font-semibold text-red-800 dark:bg-gray-800 dark:text-red-400"
566566
role="alert"
567567
>
568568
This action is irreversible, please reflect beforehand.

firebase/firestore/checkIfIDExistOnCollection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export async function checkIdAvailability(collectionName, id) {
1414
return false;
1515
}
1616
}
17+

firebase/firestore/updateFormDocument.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const useUpdateFormDocument = (collectionName) => {
4848
updateFormDocument: mutation.mutate,
4949
isLoading: mutation.isLoading,
5050
isError: mutation.isError,
51+
error: mutation.error,
5152
isSuccess: mutation.isSuccess,
5253
reset: mutation.reset,
5354
}

0 commit comments

Comments
 (0)