Function useSubmissionsByState

  • Custom React hook fetch and manage submissions filtered by their state.

    This hook is a wrapper around the useSubmissions hook, allowing you to fetch submissions and filter them by a specific state.

    Parameters

    • state: string

      The state of the submissions to filter by (e.g., "approved", "pending").

    • Optional params: SubmissionParams

      Optional additional parameters to filter or paginate the submissions:

      • projectId: The ID of the project to which the submissions belong.
      • schemaId: The ID of the schema used for filtering submissions.
      • state: The state(s) of the submissions to filter by. Can be a single state or an array of states.
      • ownerId: The ID of the owner to filter submissions by.
      • limit: The maximum number of submissions to fetch in a single query. Useful for pagination.
      • page: The page number to fetch when paginating through submissions. Typically used alongside limit.

    Returns {
        approveAll: (() => void);
        currentPage: number;
        fetchMore: ((refresh?) => Promise<void>);
        fetched: boolean;
        hasMore: boolean;
        refresh: ((quiet) => void);
        rejectAll: (() => void);
        submissions: any[];
    }

    The returning object contains:

    • submissions: The filtered list of submissions, which includes only submissions that match the specified state.
    • approveAll: Function to approve all submissions in the current list.
    • refresh: Function to refresh the list of submissions by re-fetching them from the backend. Pass quiet to suppress loading indicators.
    • rejectAll: Function to reject all submissions in the current list.
    • fetchMore: Function to fetch additional submissions beyond the current list. Pass refresh to indicate whether to refresh the existing list.
    • fetched: Boolean indicating whether the list of submissions has been fetched from the backend.
    • hasMore: Boolean indicating whether there are more submissions available to fetch.
    • currentPage: The current page of submissions that has been fetched.

    Implementation Details:

    • State Filtering: The hook filters the list of submissions based on the state property passed as an argument. Only submissions matching the provided state are included in the result.
    • Parameter Forwarding: Any additional parameters (params) are forwarded to the useSubmissions hook, allowing further filtering, pagination, or customization of the submission query.
    • Integration with useSubmissions: The hook delegates data fetching and state management to the useSubmissions hook, enhancing it with the added state filtering functionality.
    • Pagination Support: Pagination works as it does in the useSubmissions hook, allowing you to fetch additional submissions if necessary, and handle the results accordingly.
    • Error Handling: Errors from the underlying useSubmissions hook are passed through, and they should be handled as needed.
    • approveAll: (() => void)
        • (): void
        • Returns void

    • currentPage: number
    • fetchMore: ((refresh?) => Promise<void>)
        • (refresh?): Promise<void>
        • Parameters

          • Optional refresh: boolean

          Returns Promise<void>

    • fetched: boolean
    • hasMore: boolean
    • refresh: ((quiet) => void)
        • (quiet): void
        • Parameters

          • quiet: boolean

          Returns void

    • rejectAll: (() => void)
        • (): void
        • Returns void

    • submissions: any[]

    Example

    import { useSubmissionsByState } from 'react-playmakers';

    const ApprovedSubmissionsList = () => {
    const { submissions, fetchMore, refresh, fetched } = useSubmissionsByState("approved", {
    limit: 10 });

    if (!fetched) {
    return <div>Loading submissions...</div>;
    }

    return (
    <div>
    {submissions.map(submission => (
    <div key={submission.id}>{submission.name}</div>
    ))}
    <button onClick={() => fetchMore()}>Load More</button>
    <button onClick={() => refresh(false)}>Refresh</button>
    </div>
    );
    };

Generated using TypeDoc