fix: reset data after submission

This commit is contained in:
Arman committed 2023-05-23 15:05:58 +02:00
1 parent a519b0969e
commit f2622f0f78
2 files changed
+26 -9

No files matched your search

+2 -2
View File
@@ -22,13 +22,13 @@
type: 'success',
message: 'Feedback submitted successfully'
});
feedback.toggleFeedback();
feedbackData.reset();
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
} finally {
feedback.toggleFeedback();
}
}
</script>
+24 -7
View File
@@ -20,13 +20,6 @@ export type FeedbackData = {
value?: number;
};
export const feedbackData = writable<FeedbackData>({
message: '',
name: '',
email: '',
value: 0
});
export type FeedbackOption = {
type: Feedback['type'];
title: string;
@@ -51,6 +44,30 @@ export const feedbackOptions: FeedbackOption[] = [
export const selectedFeedback = writable<FeedbackOption>();
function createFeedbackDataStore() {
const { subscribe, update } = writable<FeedbackData>({
message: '',
name: '',
email: '',
value: 0
});
return {
subscribe,
update,
reset: () => {
update((feedbackData) => {
feedbackData.message = '';
feedbackData.name = '';
feedbackData.email = '';
feedbackData.value = 0;
return feedbackData;
});
}
};
}
export const feedbackData = createFeedbackDataStore();
function createFeedbackStore() {
const { subscribe, update } = writable<Feedback>({
elapsed: browser ? parseInt(localStorage.getItem('feedbackElapsed')) : 0,