diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67c5a44..05ed2be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
# @ln-dev7/sharuco
+## 1.0.1
+
+### Patch Changes
+
+- Thanks [@ln-dev7](https://github.com/ln-dev7)!
+
+**Full Changelog**: https://github.com/ln-dev7/sharuco/compare/v1.0.0...v1.0.1
+
## 1.0.0
### Major Changes
diff --git a/components/avatar-user.tsx b/components/avatar-user.tsx
index 7ba1038..f715517 100644
--- a/components/avatar-user.tsx
+++ b/components/avatar-user.tsx
@@ -50,8 +50,8 @@ export function AvatarUser() {
{data && data.exists && data.data.premium && (
-
-
+
+
)}
View form
-
- {dataForm.published
- ? "Your form is currently online and can be viewed and answered by anyone at the link"
- : "Your form is not published so can only be seen by you alone"}
-
- {isLoadingUpdateForm ? (
-
- ) : (
-
changeStatutOfForm()}
- >
- {!dataForm?.published ? "Publish" : "Unpublish"} your form
-
+ {dataForm.idAuthor === userPseudo && (
+ <>
+
+ {dataForm.published
+ ? "Your form is currently online and can be viewed and answered by anyone at the link"
+ : "Your form is not published so can only be seen by you alone"}
+
+ <>
+ {isLoadingUpdateForm ? (
+
+ ) : (
+
changeStatutOfForm()}
+ >
+ {!dataForm?.published ? "Publish" : "Unpublish"} your form
+
+ )}
+ >
+ >
)}
{isSuccessUpdateForm && (
-
-
handleAddField("heading")}
- 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"
- >
-
- Heading
-
-
handleAddField("text")}
- 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"
- >
-
- Short answer
-
-
handleAddField("longtext")}
- 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"
- >
-
- Long answer
-
-
handleAddField("link")}
- 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"
- >
-
- Link
-
- soon
-
-
-
handleAddField("email")}
- 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"
- >
-
- E-mail
-
- soon
-
-
-
-
- Unique choice
-
- soon
-
-
-
-
- Multi choice
-
- soon
-
-
-
-
- List of choices
-
- soon
-
-
-
-
- Date
-
- soon
-
-
-
-
-
+ {dataForm.idAuthor === userPseudo && (
+ <>
+
+
handleAddField("heading")}
+ 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"
+ >
+
+ Heading
+
+
handleAddField("text")}
+ 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"
+ >
+
+ Short answer
+
+
handleAddField("longtext")}
+ 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"
+ >
+
+ Long answer
+
+
handleAddField("link")}
+ 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"
+ >
+
+ Link
+
+ soon
+
+
+
handleAddField("email")}
+ 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"
+ >
+
+ E-mail
+
+ soon
+
+
+
+
+ Unique choice
+
+ soon
+
+
+
+
+ Multi choice
+
+ soon
+
+
+
+
+
+ List of choices
+
+
+ soon
+
+
+
+
+ Date
+
+ soon
+
+
+
+
+
+ >
+ )}
{errors.questions[index].text.message}
)} */}
- handleRemoveField(index)}
- >
-
-
+ {dataForm.idAuthor === userPseudo && (
+ handleRemoveField(index)}
+ >
+
+
+ )}
)
})}
@@ -390,18 +399,20 @@ export default function QuestionsForms({ dataForm }: { dataForm: any }) {
)}
-
- {isLoadingUpdateForm ? (
-
- ) : (
-
- )}
- Save questions
-
+ {dataForm.idAuthor === userPseudo && (
+
+ {isLoadingUpdateForm ? (
+
+ ) : (
+
+ )}
+ Save questions
+
+ )}
)
diff --git a/components/form/responses.tsx b/components/form/responses.tsx
index be016ae..525639c 100644
--- a/components/form/responses.tsx
+++ b/components/form/responses.tsx
@@ -243,7 +243,7 @@ export default function ResponsesForms({ dataForm }: { dataForm: any }) {
? "border-2 border-solid border-emerald-500 dark:border-emerald-900"
: ""
)}
- key={index}
+ key={response.idResponse}
>
{
+ setCheckIfUsernameExist(true)
+ checkIdAvailability("users", pseudo)
+ .then((isAvailable) => {
+ if (isAvailable) {
+ let updatedFormData = {
+ collaborators: [
+ ...dataForm.collaborators,
+ {
+ pseudo: pseudo,
+ },
+ ],
+ }
+
+ updateFormDocument({ id, updatedFormData })
+ } else {
+ toast({
+ variant: "destructive",
+ title: "This user not exist on Sharuco",
+ description: "Make sure you have entered the correct user name.",
+ action: Okay ,
+ })
+ return
+ }
+ })
+ .catch((error) => console.error("Error : ", error))
+ .finally(() => {
+ setCheckIfUsernameExist(false)
+ })
+ }
+ const removeCollaborator = async (pseudo: string) => {
+ let updatedFormData = {
+ collaborators: dataForm.collaborators.filter(
+ (item) => item.pseudo !== pseudo
+ ),
+ }
+
+ updateFormDocument({ id, updatedFormData })
+ }
+
const onSubmit = async (data) => {
const {
name: nameUpdate,
@@ -343,6 +386,74 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
)}
+
+
Team
+
+
+
+
+
Add people to manage this form.
+
+ The added persons will be able to consult the answers to your
+ form.
+
+
+
+ {
+ setUsernamePeopleToAdd(e.target.value)
+ }}
+ value={usernamePeopleToAdd}
+ />
+ {
+ setUsernamePeopleToAdd("")
+ addCollaborator(usernamePeopleToAdd)
+ }}
+ >
+ {checkIfUsernameExist && (
+
+ )}
+ Add people
+
+
+ {dataForm.collaborators.length !== 0 && (
+
+ {dataForm.collaborators.map((collaborator, index) => (
+
+
+
{
+ isLoadingUpdateForm
+ ? undefined
+ : removeCollaborator(collaborator.pseudo)
+ }}
+ >
+ Remove
+
+
+ ))}
+
+ )}
+
{/*
Payment
@@ -423,11 +534,11 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
*/}
-
-
+
+
{isLoadingUpdateForm ? (
@@ -451,7 +562,7 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
This action is irreversible, please reflect beforehand.
diff --git a/firebase/firestore/checkIfIDExistOnCollection.js b/firebase/firestore/checkIfIDExistOnCollection.js
new file mode 100644
index 0000000..b453ffe
--- /dev/null
+++ b/firebase/firestore/checkIfIDExistOnCollection.js
@@ -0,0 +1,17 @@
+import { getFirestore, collection, doc, getDoc } from 'firebase/firestore';
+
+import firebase_app from "../config"
+
+const db = getFirestore(firebase_app)
+
+export async function checkIdAvailability(collectionName, id) {
+ try {
+ const docRef = doc(collection(db, collectionName), id);
+ const docSnap = await getDoc(docRef);
+ return docSnap.exists();
+ } catch (error) {
+ console.error('Error : ', error);
+ return false;
+ }
+ }
+
diff --git a/firebase/firestore/createDocument.js b/firebase/firestore/createDocument.js
index ad51af9..ad0dbf6 100644
--- a/firebase/firestore/createDocument.js
+++ b/firebase/firestore/createDocument.js
@@ -53,6 +53,7 @@ const createDocument = async (newData, collectionName) => {
responses: newCollection.responses,
published: newCollection.published,
idAuthor: newCollection.idAuthor,
+ collaborators: newCollection.collaborators,
})
window.location.href = `/form/${newCollection.id}`
break
diff --git a/firebase/firestore/updateAllDataOnCollection.js b/firebase/firestore/updateAllDataOnCollection.js
index 31e8b35..9e10eb8 100644
--- a/firebase/firestore/updateAllDataOnCollection.js
+++ b/firebase/firestore/updateAllDataOnCollection.js
@@ -26,6 +26,12 @@ export const updateAllDatataOnCollection = async () => {
const updatePromise = updateDoc(doc.ref, { favoris })
promises.push(updatePromise)
})
+
+ // querySnapshot.docs.forEach((doc) => {
+ // const updatePromise = updateDoc(doc.ref, { collaborators: [] });
+ // promises.push(updatePromise);
+ // });
+
await Promise.all(promises)
console.log(
"La propriété a été ajoutée à tous les documents de la collection"
diff --git a/firebase/firestore/updateFormDocument.js b/firebase/firestore/updateFormDocument.js
index 5362ccb..067d267 100644
--- a/firebase/firestore/updateFormDocument.js
+++ b/firebase/firestore/updateFormDocument.js
@@ -48,6 +48,7 @@ const useUpdateFormDocument = (collectionName) => {
updateFormDocument: mutation.mutate,
isLoading: mutation.isLoading,
isError: mutation.isError,
+ error: mutation.error,
isSuccess: mutation.isSuccess,
reset: mutation.reset,
}
diff --git a/pages/form/[form]/index.tsx b/pages/form/[form]/index.tsx
index eb4254e..d9a44df 100644
--- a/pages/form/[form]/index.tsx
+++ b/pages/form/[form]/index.tsx
@@ -156,7 +156,10 @@ export default function FormPage() {
)}
{dataForm &&
dataForm.exists &&
- dataForm.data.idAuthor === userPseudo && (
+ (dataForm.data.idAuthor === userPseudo ||
+ dataForm.data.collaborators.some(
+ (item) => item.pseudo === userPseudo
+ )) && (
@@ -167,23 +170,37 @@ export default function FormPage() {
{dataForm.data.description}
-
- goToForm(value)}>
-
-
-
-
-
- Your Forms
- {dataForms.map((form) => (
-
- {form.name}
-
- ))}
-
-
-
-
+ {dataForm.data.idAuthor === userPseudo ? (
+
+ goToForm(value)}>
+
+
+
+
+
+ Your Forms
+ {dataForms.map((form) => (
+
+ {form.name}
+
+ ))}
+
+
+
+
+ ) : (
+
+ )}
@@ -203,10 +220,12 @@ export default function FormPage() {
Publish
-
-
- Settings
-
+ {dataForm.data.idAuthor === userPseudo && (
+
+
+ Settings
+
+ )}
@@ -254,28 +273,36 @@ export default function FormPage() {
-
-
-
-
-
-
-
+
+
+
+
+
+
+ )}
)}
{((dataForm && !dataForm.exists) ||
(dataForm &&
dataForm.exists &&
- dataForm.data.idAuthor !== userPseudo)) && (
+ dataForm.data.idAuthor !== userPseudo &&
+ dataForm.data.collaborators.some(
+ (item) => item.pseudo !== userPseudo
+ ))) && (
This form does not exist.
))}
+
+ Your logo here?
+