@foxpixel/react 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +457 -1
- package/dist/index.d.ts +457 -1
- package/dist/index.js +725 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +705 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -432,16 +432,721 @@ function useContactCapture() {
|
|
|
432
432
|
error
|
|
433
433
|
};
|
|
434
434
|
}
|
|
435
|
+
|
|
436
|
+
// src/blog/hooks.ts
|
|
437
|
+
import { useState as useState8, useEffect as useEffect6 } from "react";
|
|
438
|
+
function useBlogPosts(options = {}) {
|
|
439
|
+
const { client } = useFoxPixelContext();
|
|
440
|
+
const [data, setData] = useState8(null);
|
|
441
|
+
const [isLoading, setIsLoading] = useState8(true);
|
|
442
|
+
const [error, setError] = useState8(null);
|
|
443
|
+
const page = options.page ?? 0;
|
|
444
|
+
const limit = options.limit ?? 10;
|
|
445
|
+
const fetchPosts = async () => {
|
|
446
|
+
try {
|
|
447
|
+
setIsLoading(true);
|
|
448
|
+
setError(null);
|
|
449
|
+
const params = new URLSearchParams();
|
|
450
|
+
params.append("page", String(page));
|
|
451
|
+
params.append("size", String(limit));
|
|
452
|
+
const url = `/api/v1/blog/posts?${params.toString()}`;
|
|
453
|
+
const result = await client.get(url);
|
|
454
|
+
setData(result);
|
|
455
|
+
} catch (err) {
|
|
456
|
+
setError(err);
|
|
457
|
+
setData(null);
|
|
458
|
+
} finally {
|
|
459
|
+
setIsLoading(false);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
useEffect6(() => {
|
|
463
|
+
fetchPosts();
|
|
464
|
+
}, [page, limit]);
|
|
465
|
+
return {
|
|
466
|
+
data,
|
|
467
|
+
isLoading,
|
|
468
|
+
error,
|
|
469
|
+
refetch: fetchPosts
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function useBlogPost(slug) {
|
|
473
|
+
const { client } = useFoxPixelContext();
|
|
474
|
+
const [data, setData] = useState8(null);
|
|
475
|
+
const [isLoading, setIsLoading] = useState8(!!slug);
|
|
476
|
+
const [error, setError] = useState8(null);
|
|
477
|
+
const fetchPost = async () => {
|
|
478
|
+
if (!slug) {
|
|
479
|
+
setData(null);
|
|
480
|
+
setIsLoading(false);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
setIsLoading(true);
|
|
485
|
+
setError(null);
|
|
486
|
+
const result = await client.get(`/api/v1/blog/posts/${encodeURIComponent(slug)}`);
|
|
487
|
+
setData(result);
|
|
488
|
+
} catch (err) {
|
|
489
|
+
setError(err);
|
|
490
|
+
setData(null);
|
|
491
|
+
} finally {
|
|
492
|
+
setIsLoading(false);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
useEffect6(() => {
|
|
496
|
+
fetchPost();
|
|
497
|
+
}, [slug]);
|
|
498
|
+
return {
|
|
499
|
+
data,
|
|
500
|
+
isLoading,
|
|
501
|
+
error,
|
|
502
|
+
refetch: fetchPost
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function useBlogCategories() {
|
|
506
|
+
const { client } = useFoxPixelContext();
|
|
507
|
+
const [data, setData] = useState8(null);
|
|
508
|
+
const [isLoading, setIsLoading] = useState8(true);
|
|
509
|
+
const [error, setError] = useState8(null);
|
|
510
|
+
const fetchCategories = async () => {
|
|
511
|
+
try {
|
|
512
|
+
setIsLoading(true);
|
|
513
|
+
setError(null);
|
|
514
|
+
const result = await client.get("/api/v1/blog/categories");
|
|
515
|
+
setData(Array.isArray(result) ? result : []);
|
|
516
|
+
} catch (err) {
|
|
517
|
+
setError(err);
|
|
518
|
+
setData(null);
|
|
519
|
+
} finally {
|
|
520
|
+
setIsLoading(false);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
useEffect6(() => {
|
|
524
|
+
fetchCategories();
|
|
525
|
+
}, []);
|
|
526
|
+
return {
|
|
527
|
+
data,
|
|
528
|
+
isLoading,
|
|
529
|
+
error,
|
|
530
|
+
refetch: fetchCategories
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function useBlogTags() {
|
|
534
|
+
const { client } = useFoxPixelContext();
|
|
535
|
+
const [data, setData] = useState8(null);
|
|
536
|
+
const [isLoading, setIsLoading] = useState8(true);
|
|
537
|
+
const [error, setError] = useState8(null);
|
|
538
|
+
const fetchTags = async () => {
|
|
539
|
+
try {
|
|
540
|
+
setIsLoading(true);
|
|
541
|
+
setError(null);
|
|
542
|
+
const result = await client.get("/api/v1/blog/tags");
|
|
543
|
+
setData(Array.isArray(result) ? result : []);
|
|
544
|
+
} catch (err) {
|
|
545
|
+
setError(err);
|
|
546
|
+
setData(null);
|
|
547
|
+
} finally {
|
|
548
|
+
setIsLoading(false);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
useEffect6(() => {
|
|
552
|
+
fetchTags();
|
|
553
|
+
}, []);
|
|
554
|
+
return {
|
|
555
|
+
data,
|
|
556
|
+
isLoading,
|
|
557
|
+
error,
|
|
558
|
+
refetch: fetchTags
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function useBlogComments(slug) {
|
|
562
|
+
const { client } = useFoxPixelContext();
|
|
563
|
+
const [data, setData] = useState8(null);
|
|
564
|
+
const [isLoading, setIsLoading] = useState8(!!slug);
|
|
565
|
+
const [error, setError] = useState8(null);
|
|
566
|
+
const fetchComments = async () => {
|
|
567
|
+
if (!slug) {
|
|
568
|
+
setData(null);
|
|
569
|
+
setIsLoading(false);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
setIsLoading(true);
|
|
574
|
+
setError(null);
|
|
575
|
+
const result = await client.get(
|
|
576
|
+
`/api/v1/blog/posts/${encodeURIComponent(slug)}/comments`
|
|
577
|
+
);
|
|
578
|
+
setData(Array.isArray(result) ? result : []);
|
|
579
|
+
} catch (err) {
|
|
580
|
+
setError(err);
|
|
581
|
+
setData(null);
|
|
582
|
+
} finally {
|
|
583
|
+
setIsLoading(false);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
useEffect6(() => {
|
|
587
|
+
fetchComments();
|
|
588
|
+
}, [slug]);
|
|
589
|
+
return {
|
|
590
|
+
data,
|
|
591
|
+
isLoading,
|
|
592
|
+
error,
|
|
593
|
+
refetch: fetchComments
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function useBlogCommentSubmit(slug) {
|
|
597
|
+
const { client } = useFoxPixelContext();
|
|
598
|
+
const [isSubmitting, setIsSubmitting] = useState8(false);
|
|
599
|
+
const [error, setError] = useState8(null);
|
|
600
|
+
const submit = async (payload) => {
|
|
601
|
+
if (!slug) return null;
|
|
602
|
+
try {
|
|
603
|
+
setIsSubmitting(true);
|
|
604
|
+
setError(null);
|
|
605
|
+
const result = await client.post(
|
|
606
|
+
`/api/v1/blog/posts/${encodeURIComponent(slug)}/comments`,
|
|
607
|
+
payload
|
|
608
|
+
);
|
|
609
|
+
return result;
|
|
610
|
+
} catch (err) {
|
|
611
|
+
setError(err);
|
|
612
|
+
return null;
|
|
613
|
+
} finally {
|
|
614
|
+
setIsSubmitting(false);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const resetError = () => setError(null);
|
|
618
|
+
return {
|
|
619
|
+
submit,
|
|
620
|
+
isSubmitting,
|
|
621
|
+
error,
|
|
622
|
+
resetError
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function useBlogFeaturedPosts(limit = 6) {
|
|
626
|
+
const { client } = useFoxPixelContext();
|
|
627
|
+
const [data, setData] = useState8(null);
|
|
628
|
+
const [isLoading, setIsLoading] = useState8(true);
|
|
629
|
+
const [error, setError] = useState8(null);
|
|
630
|
+
const fetchFeatured = async () => {
|
|
631
|
+
try {
|
|
632
|
+
setIsLoading(true);
|
|
633
|
+
setError(null);
|
|
634
|
+
const params = new URLSearchParams();
|
|
635
|
+
params.append("page", "0");
|
|
636
|
+
params.append("size", String(limit));
|
|
637
|
+
const url = `/api/v1/blog/posts/featured?${params.toString()}`;
|
|
638
|
+
const result = await client.get(url);
|
|
639
|
+
setData(result);
|
|
640
|
+
} catch (err) {
|
|
641
|
+
setError(err);
|
|
642
|
+
setData(null);
|
|
643
|
+
} finally {
|
|
644
|
+
setIsLoading(false);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
useEffect6(() => {
|
|
648
|
+
fetchFeatured();
|
|
649
|
+
}, [limit]);
|
|
650
|
+
return {
|
|
651
|
+
data,
|
|
652
|
+
isLoading,
|
|
653
|
+
error,
|
|
654
|
+
refetch: fetchFeatured
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function useNewsletterSubscribe() {
|
|
658
|
+
const { client } = useFoxPixelContext();
|
|
659
|
+
const [isSubmitting, setIsSubmitting] = useState8(false);
|
|
660
|
+
const [error, setError] = useState8(null);
|
|
661
|
+
const [success, setSuccess] = useState8(false);
|
|
662
|
+
const subscribe = async (payload) => {
|
|
663
|
+
try {
|
|
664
|
+
setIsSubmitting(true);
|
|
665
|
+
setError(null);
|
|
666
|
+
setSuccess(false);
|
|
667
|
+
const result = await client.post(
|
|
668
|
+
"/api/v1/blog/newsletter/subscribe",
|
|
669
|
+
payload
|
|
670
|
+
);
|
|
671
|
+
setSuccess(true);
|
|
672
|
+
return result;
|
|
673
|
+
} catch (err) {
|
|
674
|
+
setError(err);
|
|
675
|
+
return null;
|
|
676
|
+
} finally {
|
|
677
|
+
setIsSubmitting(false);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
const reset = () => {
|
|
681
|
+
setError(null);
|
|
682
|
+
setSuccess(false);
|
|
683
|
+
};
|
|
684
|
+
return {
|
|
685
|
+
subscribe,
|
|
686
|
+
isSubmitting,
|
|
687
|
+
error,
|
|
688
|
+
success,
|
|
689
|
+
reset
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function useNewsletterUnsubscribe() {
|
|
693
|
+
const { client } = useFoxPixelContext();
|
|
694
|
+
const [isSubmitting, setIsSubmitting] = useState8(false);
|
|
695
|
+
const [error, setError] = useState8(null);
|
|
696
|
+
const [success, setSuccess] = useState8(false);
|
|
697
|
+
const unsubscribe = async (email) => {
|
|
698
|
+
try {
|
|
699
|
+
setIsSubmitting(true);
|
|
700
|
+
setError(null);
|
|
701
|
+
setSuccess(false);
|
|
702
|
+
await client.post("/api/v1/blog/newsletter/unsubscribe", null, {
|
|
703
|
+
params: { email }
|
|
704
|
+
});
|
|
705
|
+
setSuccess(true);
|
|
706
|
+
return true;
|
|
707
|
+
} catch (err) {
|
|
708
|
+
setError(err);
|
|
709
|
+
return false;
|
|
710
|
+
} finally {
|
|
711
|
+
setIsSubmitting(false);
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
return {
|
|
715
|
+
unsubscribe,
|
|
716
|
+
isSubmitting,
|
|
717
|
+
error,
|
|
718
|
+
success
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/blog/admin-hooks.ts
|
|
723
|
+
import { useState as useState9, useEffect as useEffect7, useCallback as useCallback2 } from "react";
|
|
724
|
+
function useAdminBlogPosts(options = {}) {
|
|
725
|
+
const { client } = useFoxPixelContext();
|
|
726
|
+
const [data, setData] = useState9(null);
|
|
727
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
728
|
+
const [error, setError] = useState9(null);
|
|
729
|
+
const page = options.page ?? 0;
|
|
730
|
+
const size = options.size ?? 20;
|
|
731
|
+
const fetchPosts = useCallback2(async () => {
|
|
732
|
+
try {
|
|
733
|
+
setIsLoading(true);
|
|
734
|
+
setError(null);
|
|
735
|
+
const params = new URLSearchParams();
|
|
736
|
+
params.append("page", String(page));
|
|
737
|
+
params.append("size", String(size));
|
|
738
|
+
const result = await client.get(`/api/blog/posts?${params.toString()}`);
|
|
739
|
+
setData(result);
|
|
740
|
+
} catch (err) {
|
|
741
|
+
setError(err);
|
|
742
|
+
} finally {
|
|
743
|
+
setIsLoading(false);
|
|
744
|
+
}
|
|
745
|
+
}, [client, page, size]);
|
|
746
|
+
useEffect7(() => {
|
|
747
|
+
fetchPosts();
|
|
748
|
+
}, [fetchPosts]);
|
|
749
|
+
return { data, isLoading, error, refetch: fetchPosts };
|
|
750
|
+
}
|
|
751
|
+
function useAdminBlogPost(id) {
|
|
752
|
+
const { client } = useFoxPixelContext();
|
|
753
|
+
const [data, setData] = useState9(null);
|
|
754
|
+
const [isLoading, setIsLoading] = useState9(!!id);
|
|
755
|
+
const [error, setError] = useState9(null);
|
|
756
|
+
const fetchPost = useCallback2(async () => {
|
|
757
|
+
if (!id) {
|
|
758
|
+
setData(null);
|
|
759
|
+
setIsLoading(false);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
try {
|
|
763
|
+
setIsLoading(true);
|
|
764
|
+
setError(null);
|
|
765
|
+
const result = await client.get(`/api/blog/posts/${id}`);
|
|
766
|
+
setData(result);
|
|
767
|
+
} catch (err) {
|
|
768
|
+
setError(err);
|
|
769
|
+
} finally {
|
|
770
|
+
setIsLoading(false);
|
|
771
|
+
}
|
|
772
|
+
}, [client, id]);
|
|
773
|
+
useEffect7(() => {
|
|
774
|
+
fetchPost();
|
|
775
|
+
}, [fetchPost]);
|
|
776
|
+
return { data, isLoading, error, refetch: fetchPost };
|
|
777
|
+
}
|
|
778
|
+
function useAdminBlogPostMutations() {
|
|
779
|
+
const { client } = useFoxPixelContext();
|
|
780
|
+
const [isLoading, setIsLoading] = useState9(false);
|
|
781
|
+
const [error, setError] = useState9(null);
|
|
782
|
+
const create = async (payload) => {
|
|
783
|
+
try {
|
|
784
|
+
setIsLoading(true);
|
|
785
|
+
setError(null);
|
|
786
|
+
const result = await client.post("/api/blog/posts", payload);
|
|
787
|
+
return result;
|
|
788
|
+
} catch (err) {
|
|
789
|
+
setError(err);
|
|
790
|
+
return null;
|
|
791
|
+
} finally {
|
|
792
|
+
setIsLoading(false);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const update = async (id, payload) => {
|
|
796
|
+
try {
|
|
797
|
+
setIsLoading(true);
|
|
798
|
+
setError(null);
|
|
799
|
+
const result = await client.put(`/api/blog/posts/${id}`, payload);
|
|
800
|
+
return result;
|
|
801
|
+
} catch (err) {
|
|
802
|
+
setError(err);
|
|
803
|
+
return null;
|
|
804
|
+
} finally {
|
|
805
|
+
setIsLoading(false);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
const remove = async (id) => {
|
|
809
|
+
try {
|
|
810
|
+
setIsLoading(true);
|
|
811
|
+
setError(null);
|
|
812
|
+
await client.delete(`/api/blog/posts/${id}`);
|
|
813
|
+
return true;
|
|
814
|
+
} catch (err) {
|
|
815
|
+
setError(err);
|
|
816
|
+
return false;
|
|
817
|
+
} finally {
|
|
818
|
+
setIsLoading(false);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
return { create, update, remove, isLoading, error };
|
|
822
|
+
}
|
|
823
|
+
function useAdminBlogCategories() {
|
|
824
|
+
const { client } = useFoxPixelContext();
|
|
825
|
+
const [data, setData] = useState9(null);
|
|
826
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
827
|
+
const [error, setError] = useState9(null);
|
|
828
|
+
const fetchCategories = useCallback2(async () => {
|
|
829
|
+
try {
|
|
830
|
+
setIsLoading(true);
|
|
831
|
+
setError(null);
|
|
832
|
+
const result = await client.get("/api/blog/categories");
|
|
833
|
+
setData(Array.isArray(result) ? result : []);
|
|
834
|
+
} catch (err) {
|
|
835
|
+
setError(err);
|
|
836
|
+
} finally {
|
|
837
|
+
setIsLoading(false);
|
|
838
|
+
}
|
|
839
|
+
}, [client]);
|
|
840
|
+
useEffect7(() => {
|
|
841
|
+
fetchCategories();
|
|
842
|
+
}, [fetchCategories]);
|
|
843
|
+
const create = async (payload) => {
|
|
844
|
+
try {
|
|
845
|
+
const result = await client.post("/api/blog/categories", payload);
|
|
846
|
+
await fetchCategories();
|
|
847
|
+
return result;
|
|
848
|
+
} catch (err) {
|
|
849
|
+
setError(err);
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
const update = async (id, payload) => {
|
|
854
|
+
try {
|
|
855
|
+
const result = await client.put(`/api/blog/categories/${id}`, payload);
|
|
856
|
+
await fetchCategories();
|
|
857
|
+
return result;
|
|
858
|
+
} catch (err) {
|
|
859
|
+
setError(err);
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
const remove = async (id) => {
|
|
864
|
+
try {
|
|
865
|
+
await client.delete(`/api/blog/categories/${id}`);
|
|
866
|
+
await fetchCategories();
|
|
867
|
+
return true;
|
|
868
|
+
} catch (err) {
|
|
869
|
+
setError(err);
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
return { data, isLoading, error, refetch: fetchCategories, create, update, remove };
|
|
874
|
+
}
|
|
875
|
+
function useAdminBlogTags() {
|
|
876
|
+
const { client } = useFoxPixelContext();
|
|
877
|
+
const [data, setData] = useState9(null);
|
|
878
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
879
|
+
const [error, setError] = useState9(null);
|
|
880
|
+
const fetchTags = useCallback2(async () => {
|
|
881
|
+
try {
|
|
882
|
+
setIsLoading(true);
|
|
883
|
+
setError(null);
|
|
884
|
+
const result = await client.get("/api/blog/tags");
|
|
885
|
+
setData(Array.isArray(result) ? result : []);
|
|
886
|
+
} catch (err) {
|
|
887
|
+
setError(err);
|
|
888
|
+
} finally {
|
|
889
|
+
setIsLoading(false);
|
|
890
|
+
}
|
|
891
|
+
}, [client]);
|
|
892
|
+
useEffect7(() => {
|
|
893
|
+
fetchTags();
|
|
894
|
+
}, [fetchTags]);
|
|
895
|
+
const create = async (payload) => {
|
|
896
|
+
try {
|
|
897
|
+
const result = await client.post("/api/blog/tags", payload);
|
|
898
|
+
await fetchTags();
|
|
899
|
+
return result;
|
|
900
|
+
} catch (err) {
|
|
901
|
+
setError(err);
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
const update = async (id, payload) => {
|
|
906
|
+
try {
|
|
907
|
+
const result = await client.put(`/api/blog/tags/${id}`, payload);
|
|
908
|
+
await fetchTags();
|
|
909
|
+
return result;
|
|
910
|
+
} catch (err) {
|
|
911
|
+
setError(err);
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
const remove = async (id) => {
|
|
916
|
+
try {
|
|
917
|
+
await client.delete(`/api/blog/tags/${id}`);
|
|
918
|
+
await fetchTags();
|
|
919
|
+
return true;
|
|
920
|
+
} catch (err) {
|
|
921
|
+
setError(err);
|
|
922
|
+
return false;
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
return { data, isLoading, error, refetch: fetchTags, create, update, remove };
|
|
926
|
+
}
|
|
927
|
+
function useAdminBlogComments(options = {}) {
|
|
928
|
+
const { client } = useFoxPixelContext();
|
|
929
|
+
const [data, setData] = useState9(null);
|
|
930
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
931
|
+
const [error, setError] = useState9(null);
|
|
932
|
+
const { status, postId, page = 0, size = 20 } = options;
|
|
933
|
+
const fetchComments = useCallback2(async () => {
|
|
934
|
+
try {
|
|
935
|
+
setIsLoading(true);
|
|
936
|
+
setError(null);
|
|
937
|
+
const params = new URLSearchParams();
|
|
938
|
+
params.append("page", String(page));
|
|
939
|
+
params.append("size", String(size));
|
|
940
|
+
if (status) params.append("status", status);
|
|
941
|
+
if (postId) params.append("postId", postId);
|
|
942
|
+
const result = await client.get(`/api/blog/comments?${params.toString()}`);
|
|
943
|
+
setData(result);
|
|
944
|
+
} catch (err) {
|
|
945
|
+
setError(err);
|
|
946
|
+
} finally {
|
|
947
|
+
setIsLoading(false);
|
|
948
|
+
}
|
|
949
|
+
}, [client, status, postId, page, size]);
|
|
950
|
+
useEffect7(() => {
|
|
951
|
+
fetchComments();
|
|
952
|
+
}, [fetchComments]);
|
|
953
|
+
const updateStatus = async (id, newStatus) => {
|
|
954
|
+
try {
|
|
955
|
+
await client.put(`/api/blog/comments/${id}/status`, { status: newStatus });
|
|
956
|
+
await fetchComments();
|
|
957
|
+
return true;
|
|
958
|
+
} catch (err) {
|
|
959
|
+
setError(err);
|
|
960
|
+
return false;
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
const remove = async (id) => {
|
|
964
|
+
try {
|
|
965
|
+
await client.delete(`/api/blog/comments/${id}`);
|
|
966
|
+
await fetchComments();
|
|
967
|
+
return true;
|
|
968
|
+
} catch (err) {
|
|
969
|
+
setError(err);
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
return { data, isLoading, error, refetch: fetchComments, updateStatus, remove };
|
|
974
|
+
}
|
|
975
|
+
function useAdminNewsletterSubscribers(options = {}) {
|
|
976
|
+
const { client } = useFoxPixelContext();
|
|
977
|
+
const [data, setData] = useState9(null);
|
|
978
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
979
|
+
const [error, setError] = useState9(null);
|
|
980
|
+
const { status, page = 0, size = 20 } = options;
|
|
981
|
+
const fetchSubscribers = useCallback2(async () => {
|
|
982
|
+
try {
|
|
983
|
+
setIsLoading(true);
|
|
984
|
+
setError(null);
|
|
985
|
+
const params = new URLSearchParams();
|
|
986
|
+
params.append("page", String(page));
|
|
987
|
+
params.append("size", String(size));
|
|
988
|
+
if (status) params.append("status", status);
|
|
989
|
+
const result = await client.get(`/api/blog/newsletter/subscribers?${params.toString()}`);
|
|
990
|
+
setData(result);
|
|
991
|
+
} catch (err) {
|
|
992
|
+
setError(err);
|
|
993
|
+
} finally {
|
|
994
|
+
setIsLoading(false);
|
|
995
|
+
}
|
|
996
|
+
}, [client, status, page, size]);
|
|
997
|
+
useEffect7(() => {
|
|
998
|
+
fetchSubscribers();
|
|
999
|
+
}, [fetchSubscribers]);
|
|
1000
|
+
const remove = async (id) => {
|
|
1001
|
+
try {
|
|
1002
|
+
await client.delete(`/api/blog/newsletter/subscribers/${id}`);
|
|
1003
|
+
await fetchSubscribers();
|
|
1004
|
+
return true;
|
|
1005
|
+
} catch (err) {
|
|
1006
|
+
setError(err);
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
return { data, isLoading, error, refetch: fetchSubscribers, remove };
|
|
1011
|
+
}
|
|
1012
|
+
function useAdminNewsletterStats() {
|
|
1013
|
+
const { client } = useFoxPixelContext();
|
|
1014
|
+
const [data, setData] = useState9(null);
|
|
1015
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
1016
|
+
const [error, setError] = useState9(null);
|
|
1017
|
+
const fetchStats = useCallback2(async () => {
|
|
1018
|
+
try {
|
|
1019
|
+
setIsLoading(true);
|
|
1020
|
+
setError(null);
|
|
1021
|
+
const result = await client.get("/api/blog/newsletter/stats");
|
|
1022
|
+
setData(result);
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
setError(err);
|
|
1025
|
+
} finally {
|
|
1026
|
+
setIsLoading(false);
|
|
1027
|
+
}
|
|
1028
|
+
}, [client]);
|
|
1029
|
+
useEffect7(() => {
|
|
1030
|
+
fetchStats();
|
|
1031
|
+
}, [fetchStats]);
|
|
1032
|
+
return { data, isLoading, error, refetch: fetchStats };
|
|
1033
|
+
}
|
|
1034
|
+
function useAdminBlogSettings() {
|
|
1035
|
+
const { client } = useFoxPixelContext();
|
|
1036
|
+
const [data, setData] = useState9(null);
|
|
1037
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
1038
|
+
const [error, setError] = useState9(null);
|
|
1039
|
+
const fetchSettings = useCallback2(async () => {
|
|
1040
|
+
try {
|
|
1041
|
+
setIsLoading(true);
|
|
1042
|
+
setError(null);
|
|
1043
|
+
const result = await client.get("/api/blog/settings");
|
|
1044
|
+
setData(result);
|
|
1045
|
+
} catch (err) {
|
|
1046
|
+
setError(err);
|
|
1047
|
+
} finally {
|
|
1048
|
+
setIsLoading(false);
|
|
1049
|
+
}
|
|
1050
|
+
}, [client]);
|
|
1051
|
+
useEffect7(() => {
|
|
1052
|
+
fetchSettings();
|
|
1053
|
+
}, [fetchSettings]);
|
|
1054
|
+
const update = async (settings) => {
|
|
1055
|
+
try {
|
|
1056
|
+
const result = await client.put("/api/blog/settings", settings);
|
|
1057
|
+
setData(result);
|
|
1058
|
+
return result;
|
|
1059
|
+
} catch (err) {
|
|
1060
|
+
setError(err);
|
|
1061
|
+
return null;
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
return { data, isLoading, error, refetch: fetchSettings, update };
|
|
1065
|
+
}
|
|
1066
|
+
function useAdminBlogAnalytics() {
|
|
1067
|
+
const { client } = useFoxPixelContext();
|
|
1068
|
+
const [data, setData] = useState9(null);
|
|
1069
|
+
const [isLoading, setIsLoading] = useState9(true);
|
|
1070
|
+
const [error, setError] = useState9(null);
|
|
1071
|
+
const fetchAnalytics = useCallback2(async () => {
|
|
1072
|
+
try {
|
|
1073
|
+
setIsLoading(true);
|
|
1074
|
+
setError(null);
|
|
1075
|
+
const result = await client.get("/api/blog/analytics/summary");
|
|
1076
|
+
setData(result);
|
|
1077
|
+
} catch (err) {
|
|
1078
|
+
setError(err);
|
|
1079
|
+
} finally {
|
|
1080
|
+
setIsLoading(false);
|
|
1081
|
+
}
|
|
1082
|
+
}, [client]);
|
|
1083
|
+
useEffect7(() => {
|
|
1084
|
+
fetchAnalytics();
|
|
1085
|
+
}, [fetchAnalytics]);
|
|
1086
|
+
return { data, isLoading, error, refetch: fetchAnalytics };
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// src/blog/utils.ts
|
|
1090
|
+
function getBlogPostSchemaLd(post, options) {
|
|
1091
|
+
const { siteUrl, publisherName, publisherLogoUrl } = options;
|
|
1092
|
+
const postUrl = `${siteUrl.replace(/\/$/, "")}/blog/${post.slug}`;
|
|
1093
|
+
const schema = {
|
|
1094
|
+
"@context": "https://schema.org",
|
|
1095
|
+
"@type": "BlogPosting",
|
|
1096
|
+
headline: post.title,
|
|
1097
|
+
description: post.metaDescription || post.excerpt || void 0,
|
|
1098
|
+
image: post.coverImageUrl || void 0,
|
|
1099
|
+
datePublished: post.publishedAt || void 0,
|
|
1100
|
+
dateModified: post.updatedAt,
|
|
1101
|
+
mainEntityOfPage: {
|
|
1102
|
+
"@type": "WebPage",
|
|
1103
|
+
"@id": postUrl
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
if (publisherName || publisherLogoUrl) {
|
|
1107
|
+
schema.publisher = {
|
|
1108
|
+
"@type": "Organization",
|
|
1109
|
+
...publisherName && { name: publisherName },
|
|
1110
|
+
...publisherLogoUrl && {
|
|
1111
|
+
logo: {
|
|
1112
|
+
"@type": "ImageObject",
|
|
1113
|
+
url: publisherLogoUrl
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
return schema;
|
|
1119
|
+
}
|
|
435
1120
|
export {
|
|
436
1121
|
AuthProvider,
|
|
437
1122
|
FoxPixelHttpClient,
|
|
438
1123
|
FoxPixelProvider,
|
|
439
1124
|
GuestOnlyRoute,
|
|
440
1125
|
ProtectedRoute,
|
|
1126
|
+
getBlogPostSchemaLd,
|
|
1127
|
+
useAdminBlogAnalytics,
|
|
1128
|
+
useAdminBlogCategories,
|
|
1129
|
+
useAdminBlogComments,
|
|
1130
|
+
useAdminBlogPost,
|
|
1131
|
+
useAdminBlogPostMutations,
|
|
1132
|
+
useAdminBlogPosts,
|
|
1133
|
+
useAdminBlogSettings,
|
|
1134
|
+
useAdminBlogTags,
|
|
1135
|
+
useAdminNewsletterStats,
|
|
1136
|
+
useAdminNewsletterSubscribers,
|
|
441
1137
|
useAuth,
|
|
1138
|
+
useBlogCategories,
|
|
1139
|
+
useBlogCommentSubmit,
|
|
1140
|
+
useBlogComments,
|
|
1141
|
+
useBlogFeaturedPosts,
|
|
1142
|
+
useBlogPost,
|
|
1143
|
+
useBlogPosts,
|
|
1144
|
+
useBlogTags,
|
|
442
1145
|
useContactCapture,
|
|
443
1146
|
useFoxPixelContext,
|
|
444
1147
|
useLeadCapture,
|
|
1148
|
+
useNewsletterSubscribe,
|
|
1149
|
+
useNewsletterUnsubscribe,
|
|
445
1150
|
useServices,
|
|
446
1151
|
withAuth
|
|
447
1152
|
};
|