Skip to content

Commit

Permalink
feat: use comment-worker instead of staticman
Browse files Browse the repository at this point in the history
  • Loading branch information
zanechua committed Aug 14, 2023
1 parent 17b7b5d commit 8f67de0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/components/CommentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ const CommentForm = ({ slug, className }) => {
const handleSubmission = async () => {
setIsLoading(true);
setConfirmationMessage('');
const formData = new URLSearchParams();
formData.append('fields[slug]', slug);
formData.append('fields[name]', name);
formData.append('fields[email]', email);
formData.append('fields[message]', message);

if (name === '' || email === '' || message === '') {
setIsLoading(false);
setConfirmationMessage('Uh oh. Did you miss something?');
} else {
fetch('https://staticman.zanechua.com/v2/entry/zanechua/website/master/comments', {
fetch('https://comments.zanechua.com/api/handle/form', {
method: 'POST',
data: formData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
body: JSON.stringify({
fields: {
slug,
name,
email,
message
}
}),
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
if (response.status === 200) {
if (response.status === 200 || response.status === 201) {
resetInputData();
setConfirmationMessage(
'Thanks! Your comment will be published after it has been reviewed.'
Expand Down
6 changes: 1 addition & 5 deletions staticman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ comments:
# not here is part of the request, an error will be thrown.
allowedFields: ['name', 'email', 'url', 'message', 'slug']

# When allowedOrigins is defined, only requests sent from one of the domains
# listed will be accepted.
allowedOrigins: ["zanechua.com"]

auth:
required: false

Expand Down Expand Up @@ -81,4 +77,4 @@ comments:
# List of transformations to apply to any of the fields supplied. Keys are
# the name of the field and values are possible transformation types.
transforms:
email: md5
email: sha512

0 comments on commit 8f67de0

Please sign in to comment.