Abhinav 1 gadu atpakaļ
vecāks
revīzija
22605e503c

+ 13 - 7
apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipant.tsx

@@ -39,23 +39,29 @@ export default function AddParticipant({
         [emailList, collection.sharees]
     );
 
-    const collectionShare: AddParticipantFormProps['callback'] = async (
-        emails
-    ) => {
-        if (emails.length === 1) {
-            if (emails[0] === user.email) {
+    const collectionShare: AddParticipantFormProps['callback'] = async ({
+        email,
+        emails,
+    }) => {
+        // if email is provided, means user has custom entered email, so, will need to validate for self sharing
+        // and already shared
+        if (email) {
+            if (email === user.email) {
                 throw new Error(t('SHARE_WITH_SELF'));
             } else if (
-                collection?.sharees?.find((value) => value.email === emails[0])
+                collection?.sharees?.find((value) => value.email === email)
             ) {
-                throw new Error(t('ALREADY_SHARED', { email: emails[0] }));
+                throw new Error(t('ALREADY_SHARED', { email: email }));
             }
+            // set emails to array of one email
+            emails = [email];
         }
         for (const email of emails) {
             if (
                 email === user.email ||
                 collection?.sharees?.find((value) => value.email === email)
             ) {
+                // can just skip this email
                 continue;
             }
             try {

+ 3 - 3
apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx

@@ -18,7 +18,7 @@ interface formValues {
     selectedOptions: string[];
 }
 export interface AddParticipantFormProps {
-    callback: (emails: string[]) => Promise<void>;
+    callback: (props: { email?: string; emails?: string[] }) => Promise<void>;
     fieldType: 'text' | 'email' | 'password';
     placeholder: string;
     buttonText: string;
@@ -49,9 +49,9 @@ export default function AddParticipantForm(props: AddParticipantFormProps) {
         try {
             SetLoading(true);
             if (values.inputValue !== '') {
-                await props.callback([values.inputValue]);
+                await props.callback({ email: values.inputValue });
             } else if (values.selectedOptions.length !== 0) {
-                await props.callback(values.selectedOptions);
+                await props.callback({ emails: values.selectedOptions });
             }
             SetLoading(false);
             props.onClose();