Skip to content

Commit

Permalink
feat: add user meta data along news letter sub
Browse files Browse the repository at this point in the history
  • Loading branch information
Zain-ul-din committed Jun 8, 2024
1 parent 61f83fb commit 2aac129
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/design/md/NewLetter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
Heading,
Input
} from '@chakra-ui/react';
import { doc, setDoc } from 'firebase/firestore';
import { doc, serverTimestamp, setDoc } from 'firebase/firestore';
import { useState } from 'react';
import { useUserCredentials } from '~/hooks/hooks';
import { newsLetterColRef } from '~/lib/firebase';

export default function NewsLetter({ uid }: { uid: string }) {
Expand All @@ -20,6 +21,8 @@ export default function NewsLetter({ uid }: { uid: string }) {
const [response, setResponse] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);

const [user] = useUserCredentials();

const validateEmail = (value: string) => {
// Regular expression for email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Expand All @@ -35,7 +38,12 @@ export default function NewsLetter({ uid }: { uid: string }) {
await setDoc(
doc(newsLetterColRef, `${email}_${uid}`),
{
email
email,
createdBy: user ? user.uid : '',
userMail: user ? user.email : '',
userName: user ? user.displayName : '',
photoURL: user ? user.photoURL : '',
created_at: serverTimestamp()
},
{
merge: true
Expand Down

0 comments on commit 2aac129

Please sign in to comment.