@open-tender/utils
Version:
A library of utils for use with Open Tender applications that utilize our cloud-based Order API.
35 lines (34 loc) • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useOrderRating = void 0;
const react_1 = require("react");
const useOrderRating = (orderId, orderRating, updateRating) => {
const [rating, setRating] = (0, react_1.useState)((orderRating && orderRating.rating) || 0);
const [comments, setComments] = (0, react_1.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
};
};
exports.useOrderRating = useOrderRating;