You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know what can be happening, but this works fine in production but on localhost nothing happens (state is never updated), neither with npm run dev nor npm run start
useEffect(() => {
//THIS CONSOLE LOG ONLY WORKS IN MOUNTING, THEN STATE NOT UPDATED
console.log("state: ", state);
if (state?.success) {
setOpenAction(false);
toast.success(state.success);
}
}, [state]);
return (
Leave feedback
We'd love to hear what well or how we can improve the product experience.
const validatedFields = z
.object({
feedback: z.string().min(1, { message: "Feedback must be at least 1 character" }),
rating: z.string().trim().refine((value) => ["good", "bad", "neutral"].includes(value), {
message: "Rating must be either 'good', 'bad', or 'neutral'",
}).optional(),
})
.safeParse({ feedback, rating });
if (!validatedFields.success) {
return {
errors: validatedFields.error.flatten().fieldErrors,
};
}
const user = await getUser();
if (!user) {
throw new Error("We couldn't find your account. Please try again.");
}
return {
success: "Thank you for your feedback!"
};
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know what can be happening, but this works fine in production but on localhost nothing happens (state is never updated), neither with npm run dev nor npm run start
'use client'
export function FeedbackDialog({ open, setOpenAction }: { open: boolean; setOpenAction: Dispatch<SetStateAction> }) {
const [state, action, processing] = useActionState(submitFeedback, initialState);
const [rating, setRating] = useState("");
useEffect(() => {
setRating("");
}, [open]);
useEffect(() => {
//THIS CONSOLE LOG ONLY WORKS IN MOUNTING, THEN STATE NOT UPDATED
console.log("state: ", state);
if (state?.success) {
setOpenAction(false);
toast.success(state.success);
}
}, [state]);
return (
Leave feedback
We'd love to hear what well or how we can improve the product experience.
...
'use server'
export async function submitFeedback(state: FeedbackState, formData: FormData) {
const fields = formData.entries();
const data = Object.fromEntries(fields);
const { feedback, rating } = data;
const validatedFields = z
.object({
feedback: z.string().min(1, { message: "Feedback must be at least 1 character" }),
rating: z.string().trim().refine((value) => ["good", "bad", "neutral"].includes(value), {
message: "Rating must be either 'good', 'bad', or 'neutral'",
}).optional(),
})
.safeParse({ feedback, rating });
if (!validatedFields.success) {
return {
errors: validatedFields.error.flatten().fieldErrors,
};
}
const user = await getUser();
if (!user) {
throw new Error("We couldn't find your account. Please try again.");
}
return {
success: "Thank you for your feedback!"
};
}
Beta Was this translation helpful? Give feedback.
All reactions