Skip to content

Commit

Permalink
Merge pull request #372 from credebl/fix-pre-prod-issues
Browse files Browse the repository at this point in the history
Fix: pre prod issues
  • Loading branch information
nishad-ayanworks authored Oct 19, 2023
2 parents 5e281fb + 58177be commit 4d1e591
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions src/components/organization/invitations/SendInvitationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { useEffect, useState } from 'react';

import { AlertComponent } from '../../AlertComponent';
import type { AxiosResponse } from 'axios';
import { apiStatusCodes } from '../../../config/CommonConstant';
import { apiStatusCodes, storageKeys } from '../../../config/CommonConstant';
import {
createEcoSystemInvitations,
createInvitations,
} from '../../../api/invitations';
import { getOrganizationRoles } from '../../../api/organization';
import { getFromLocalStorage } from '../../../api/Auth';

interface Values {
email: string;
Expand All @@ -29,14 +30,18 @@ interface RoleI {
}

const SendInvitationModal = (props: {
getAllSentInvitations?: ()=> void;
ecosystemId? : string;
getAllSentInvitations?: () => void;
ecosystemId?: string;
flag?: boolean;
openModal: boolean;
setMessage: (message: string) => void;
setOpenModal: (flag: boolean) => void;
}) => {
const [loading, setLoading] = useState<boolean>(false);
const [selfEmail, setSelfEmail] = useState({
email: "",
error: ""
});

const [invitations, setInvitations] = useState<Invitations[]>([]);

Expand Down Expand Up @@ -143,14 +148,26 @@ const SendInvitationModal = (props: {
}
setLoading(false);
};

useEffect(() => {
const getEmail = async () => {
const email = await getFromLocalStorage(storageKeys.USER_EMAIL)
setSelfEmail({
...selfEmail,
email
})
}
getEmail()
}, [])

return (
<Modal
size="2xl"
show={props.openModal}
onClose={() => {
setInvitations([]);
setInitialInvitationData({
email:" ",
email: " ",
});
props.setOpenModal(false);
}}
Expand Down Expand Up @@ -180,6 +197,17 @@ const SendInvitationModal = (props: {
values: Values,
{ resetForm }: FormikHelpers<Values>,
) => {
if(values.email === selfEmail.email){
setSelfEmail({
...selfEmail,
error: "You can't send invitation to self."
})
return
}
setSelfEmail({
...selfEmail,
error: ""
})
await includeInvitation(values);
resetForm({ values: initialInvitationData });
}}
Expand All @@ -195,19 +223,27 @@ const SendInvitationModal = (props: {
<Label htmlFor="email2" value="Email" />
<span className="text-red-500 text-xs">*</span>
</div>
<Field
<input
id="email"
name="email"
className="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
onChange={(e) => {
formikHandlers.handleChange(e)
}}
/>
{formikHandlers?.errors?.email &&
formikHandlers?.touched?.email ? (
formikHandlers?.touched?.email ? (
<span className="text-red-500 text-xs">
{formikHandlers?.errors?.email}
</span>
) : (
<span className="invisible text-xs">Error</span>
)}
) : selfEmail.error ?
<span className="text-red-500 text-xs">
{selfEmail.error}
</span>
:
(
<span className="invisible text-xs">Error</span>
)}
</div>

<div className="">
Expand Down

0 comments on commit 4d1e591

Please sign in to comment.