Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: pre prod issues #372

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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