UNPKG

@open-tender/utils

Version:

A library of utils for use with Open Tender applications that utilize our cloud-based Order API.

31 lines (30 loc) 997 B
import { useState } from 'react'; export const useOrderRating = (orderId, orderRating, updateRating) => { const [rating, setRating] = useState((orderRating && orderRating.rating) || 0); const [comments, setComments] = useState((orderRating && orderRating.comments) || ''); const stars = [1, 2, 3, 4, 5]; const handleRating = (star) => { setRating(star); }; const handleComments = (inputComments) => { setComments(inputComments); }; const handleSubmit = (evt) => { evt === null || evt === void 0 ? void 0 : evt.preventDefault(); const data = { rating, comments }; updateRating(orderId, data); }; const handleClose = () => { setComments((orderRating && orderRating.comments) || ''); setRating((orderRating && orderRating.rating) || 0); }; return { rating, handleRating, comments, handleComments, handleSubmit, handleClose, stars }; };