Adjust product state transitions
This commit is contained in:
@ -1197,7 +1197,7 @@ function EditProductPageInner() {
|
||||
}
|
||||
}
|
||||
|
||||
function buildPayload(state?: "DRAFT" | "PUBLISHED") {
|
||||
function buildPayload(state?: "DRAFT" | "REVIEW") {
|
||||
if (!form) return null;
|
||||
const resolvedState = state ?? "DRAFT";
|
||||
const base = {
|
||||
@ -1312,7 +1312,7 @@ function EditProductPageInner() {
|
||||
setErrorLogCopied(false);
|
||||
|
||||
try {
|
||||
const payload = buildPayload("PUBLISHED");
|
||||
const payload = buildPayload("REVIEW");
|
||||
|
||||
const res = await fetch("/api/products/create", {
|
||||
method: "POST",
|
||||
@ -1343,7 +1343,7 @@ function EditProductPageInner() {
|
||||
setErrorLogCopied(false);
|
||||
|
||||
try {
|
||||
const payload = buildPayload();
|
||||
const payload = buildPayload("REVIEW");
|
||||
|
||||
const res = await fetch(`/api/products/${params.productId}`, {
|
||||
method: "PUT",
|
||||
@ -1356,16 +1356,6 @@ function EditProductPageInner() {
|
||||
throw new Error(result?.responseDesc || "Gagal menyimpan produk");
|
||||
}
|
||||
|
||||
const reviewRes = await fetch(`/api/products/submit-review/${params.productId}`, {
|
||||
method: "POST",
|
||||
headers: { "x-auth-token": getToken() },
|
||||
});
|
||||
const reviewResult = await reviewRes.json();
|
||||
if (!reviewRes.ok) {
|
||||
setErrorLog({ request: { submitReview: params.productId }, response: reviewResult });
|
||||
throw new Error(reviewResult?.responseDesc || "Gagal mengirim produk ke review");
|
||||
}
|
||||
|
||||
setSaveSuccess(true);
|
||||
setTimeout(() => router.back(), 1500);
|
||||
} catch (err) {
|
||||
|
||||
@ -97,7 +97,7 @@ export default function ProductReviewPage() {
|
||||
async function handleSubmitForReview() {
|
||||
setErrorLogCopied(false);
|
||||
try {
|
||||
await submit("PUBLISHED");
|
||||
await submit("REVIEW");
|
||||
router.push("/products/new/submitted");
|
||||
} catch {
|
||||
// error is set by the hook
|
||||
|
||||
Reference in New Issue
Block a user