Function useSubmissionsBySchema

  • Custom React hook to fetch and manage submissions filtered by their schema ID.

    This hook is a wrapper around the useSubmissions hook, allowing you to fetch submissions associated with a specific schema ID and optionally pass additional parameters for filtering or pagination.

    Parameters

    • schemaId: string

      The schema ID to filter submissions by.

    • 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 UseSubmissionsValue

    The returning object contains:

    • submissions: The list of submissions filtered by the provided schemaId.
    • 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:

    • Schema Filtering: The hook automatically filters submissions by the provided schemaId. Only submissions associated with the given schema ID will be 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: This hook delegates data fetching and state management to the useSubmissions hook, with the added benefit of only fetching submissions that match the given schema ID.
    • Pagination Support: Pagination works as it does in the useSubmissions hook, allowing you to fetch more 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.

    Example Usage:

    import { useSubmissionsBySchema } from 'react-playmakers';

    const SubmissionsBySchemaList = () => {
    const { submissions, fetchMore, refresh, fetched } = useSubmissionsBySchema("sXXXXXXXX", {
    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