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

#578 Improving search invitation to listern to typing event #591

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions src/components/InvitationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ function DataTableStats({ data, columns, error, loading }: TableData) {
setPageIndex(currentPageIndex);
}, [currentPageIndex]);

useEffect(() => {
if (error) {
toast.error('Network error. Please, try again later.');
}
}, [error]);

const handleFilterChange = (e) => {
const value = e.target.value || '';
setGlobalFilter(value);
Expand Down
30 changes: 17 additions & 13 deletions src/pages/invitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ function Invitation() {
] = useLazyQuery(GET_INVITATIONS, {
variables: {
query: searchQuery,
orgToken: organizationToken,
sortBy:sortBy
orgToken: organizationToken
},
fetchPolicy: 'network-only',
});
Expand All @@ -222,8 +221,7 @@ function Invitation() {
variables: {
role: filterVariables.role || null,
status:filterVariables.status || null,
orgToken: organizationToken,
sortBy:sortBy
orgToken: organizationToken
},
});
}
Expand Down Expand Up @@ -269,8 +267,10 @@ function Invitation() {

const handleSearch = () => {
if (!searchQuery.trim()) {
setError('Search query cannot be empty');
return;
if (data && data.getAllInvitations) {
setInvitations(data.getAllInvitations.invitations);
setTotalInvitations(data.getAllInvitations.totalInvitations);
}
}

setInvitations([]);
Expand All @@ -280,6 +280,14 @@ function Invitation() {
fetchInvitations({ variables: { query: searchQuery } });
};

useEffect(() => {
const delayDebounceFn = setTimeout(() => {
handleSearch();
}, 500);

return () => clearTimeout(delayDebounceFn);
}, [searchQuery]);


useEffect(() => {
if (selectedRole || selectedStatus) {
Expand Down Expand Up @@ -324,8 +332,6 @@ const handleStatusChange=(e:React.ChangeEvent<HTMLSelectElement>)=>{
setSelectedRow(selectedRow === row ? null : row);
};

const disabledSearch = !searchQuery.trim();

interface EmailInputProps {
email: string;
setEmail: (email: string) => void;
Expand Down Expand Up @@ -820,21 +826,19 @@ setSortBy(sortBy)
The “Search bar” below enables you to effortlessly check the status of
sent invitations.
<br />
Simply type in the email or name of the invitee in the search bar to
Simply type in the email, or role of the invitee or status of the invitation in the search bar to
instantly retrieve real-time updates.
</p>

{/* Search form */}
<div className='block lg:flex justify-between items-center'>
<div className="flex flex-row md:flex-row gap-2 md:gap-2 md:w-[50%] w-full">
<div className="relative flex-1 text-black ">
<div className="relative flex-1 text-black">
<input
type="text"
id="search"
value={searchQuery}
onChange={(e) => {
setSearchQuery(e.target.value)
}}
onChange={(e) => setSearchQuery(e.target.value)}
placeholder="Search by email, role or status of the invitation."
className="border border-gray-300 outline-none bg-transparent rounded-md pl-10 pr-4 py-1 w-full dark:text-white hover:border-[#7258ce] dark:text:text-white sm:text-normal text-md dark:bg-[#04122F]"
/>
Expand Down
12 changes: 6 additions & 6 deletions src/queries/invitation.queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { gql } from "@apollo/client";


export const GET_ALL_INVITATIONS = gql`
query AllInvitations($limit: Int, $offset: Int,$orgToken: String!,$sortBy:Int) {
getAllInvitations(limit: $limit, offset: $offset,orgToken: $orgToken,sortBy:$sortBy) {
query AllInvitations($limit: Int, $offset: Int,$orgToken: String!) {
getAllInvitations(limit: $limit, offset: $offset,orgToken: $orgToken) {
invitations {
invitees {
email
Expand All @@ -18,8 +18,8 @@ export const GET_ALL_INVITATIONS = gql`
`;

export const GET_INVITATIONS = gql`
query GetInvitations($query: String!, $limit: Int, $offset: Int,$orgToken: String!,$sortBy:Int) {
getInvitations(query: $query, limit: $limit, offset: $offset,orgToken: $orgToken,,sortBy:$sortBy) {
query GetInvitations($query: String!, $limit: Int, $offset: Int,$orgToken: String!) {
getInvitations(query: $query, limit: $limit, offset: $offset,orgToken: $orgToken) {
invitations {
invitees {
email
Expand All @@ -33,8 +33,8 @@ export const GET_INVITATIONS = gql`
`;

export const GET_ROLES_AND_STATUSES = gql`
query filterInvitations($limit: Int, $offset: Int, $role: String, $status: String, $orgToken: String!,$sortBy:Int) {
filterInvitations(limit: $limit, offset: $offset, role: $role, status: $status, orgToken: $orgToken,sortBy:$sortBy) {
query filterInvitations($limit: Int, $offset: Int, $role: String, $status: String, $orgToken: String!) {
filterInvitations(limit: $limit, offset: $offset, role: $role, status: $status, orgToken: $orgToken) {
invitations {
invitees {
email
Expand Down
Loading