@@ -32,7 +32,6 @@ import { Icon } from 'astro-icon/components';
3232
3333<script >
3434 type FeedbackType = 'like' | 'dislike';
35- import { createDirectus, rest, createItem } from '@directus/sdk';
3635
3736 function getFeedbackForm(): HTMLElement {
3837 return document.getElementById('feedback-form') as HTMLElement;
@@ -110,34 +109,39 @@ import { Icon } from 'astro-icon/components';
110109
111110 async function submitFeedback() {
112111 const comment = getCommentTextarea().value.trim();
112+ const feedbackType = getFeedbackForm().dataset.feedbackType as FeedbackType;
113113
114- if (!comment) {
114+ // A comment is only mandatory for dislikes.
115+ if (feedbackType === 'dislike' && !comment) {
115116 getErrorMessage().classList.remove('hidden');
116117 getCommentTextarea().focus();
117118 return;
118119 }
119120
120- const host = import.meta.env.PUBLIC_DIRECTUS_HOST;
121- const feedbackType = getFeedbackForm().dataset.feedbackType as FeedbackType;
121+ const host = import.meta.env.PUBLIC_STORE_API_HOST;
122122
123123 if (!host) {
124- console.error('Directus host is not set');
124+ console.error('Store API host is not set');
125125 closeForm(feedbackType);
126126 return;
127127 }
128128
129- const client = createDirectus(host).with(rest());
130-
131129 try {
132- await client.request(
133- createItem('feedback' as never, {
130+ const response = await fetch(`${host}/api/feedback/submit`, {
131+ method: 'POST',
132+ headers: { 'Content-Type': 'application/json' },
133+ body: JSON.stringify({
134134 type: feedbackType,
135135 page: window.location.pathname,
136- comment: comment,
137- })
138- );
136+ ...(comment ? { comment } : {}),
137+ }),
138+ });
139+
140+ if (!response.ok) {
141+ console.error(`Feedback submission failed: ${response.status}`);
142+ }
139143 } catch (error) {
140- console.log (error);
144+ console.error (error);
141145 }
142146
143147 closeForm(feedbackType);
0 commit comments