• Custom React hook to manage submission data and operations such as fetching, creating, updating, approving, rejecting, and deleting submissions.

    Parameters

    • initId: null | string

      The initial ID of the submission to fetch or null if starting with no submission.

    • checkForPending: boolean = false

      A flag to enable polling for pending submissions. Defaults to false.

    Returns UseSubmissionValue

    The returning object contains:

    • submission: The current submission object containing all submission details.
    • fetched: Boolean indicating whether the submission data has been fetched.
    • isPending: Boolean indicating if the submission is in a pending state, or null if the state is unknown.
    • uploadPendingAfterTimeout: Boolean indicating if the submission upload is still pending after exceeding the timeout period.
    • push: Function to push updated submission data to the backend.
    • pushSubmission: Alias for the push method.
    • deleteSubmission: Function to delete the submission by ID or use the current submission ID.
    • setDescription: Function to update the description of the submission.
    • setFiles: Function to update the files associated with the submission.
    • setName: Function to update the name of the submission.
    • setPostTitle: Function to update the post title of the submission.
    • setState: Function to update the state of the submission.
    • setId: Function to update the ID of the submission and trigger a refetch.
    • setSchemaId: Function to update the schema ID of the submission.
    • approve: Function to approve the submission, optionally adding a comment.
    • approveSubmission: Alias for the approve method.
    • reject: Function to reject the submission, optionally adding a comment.
    • rejectSubmission: Alias for the reject method.
    • reset: Function to reset the submission state to default values.
    • refetch: Function to refetch the submission data from the backend. Pass quiet to avoid triggering loading indicators.

    Example

    import { useSubmission } from 'react-playmakers';

    const MyComponent = () => {
    const {
    submission,
    approve,
    reject,
    setName,
    setPostTitle,
    setSchemaId,
    push,
    refetch,
    deleteSubmission
    } = useSubmission('SXXXXXXXX', true);

    const handleApprove = () => {
    approve('Great submission!');
    };

    const handleUpdate = async () => {
    setName('Updated Submission Name');
    setPostTitle('New Post Title');
    setSchemaId('schema-001');
    await push(); // Push updated submission to the backend
    };

    const handleDelete = () => {
    deleteSubmission(submission.id);
    };

    return (
    <div>
    <h1>Submission: {submission.name}</h1>
    <button onClick={handleApprove}>Approve</button>
    <button onClick={handleUpdate}>Update</button>
    <button onClick={refetch}>Refetch</button>
    <button onClick={handleDelete}>Delete</button>
    </div>
    );
    };

Generated using TypeDoc