This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function contactView(id) { | |
try { | |
const contact = await Contact.findById(id); | |
const newContact = { ...contact._doc, _id: contact._doc._id.toString() }; | |
return newContact; | |
} catch (e) { | |
return { error: e.message }; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client'; | |
import { contactView } from '@/actions/actions'; | |
import React, { useState } from 'react'; | |
import { CiTrash, CiEdit, CiRead } from 'react-icons/ci'; | |
import Delete from './delete'; | |
import View from './view'; | |
import Edit from './edit'; | |
function Table({ contacts }) { | |
const [currId, setCurrId] = useState(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { contactList } from '@/actions/actions'; | |
import Table from '@/components/table'; | |
export default async function Home() { | |
const { contacts } = await contactList(); | |
return ( | |
<div className="container mx-auto mb-16"> | |
<h3 className="text-3xl mb-4">MY AMAZING CONTACTS</h3> | |
<div className="mb-4"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as z from 'zod'; | |
const zSchema = z.object({ | |
name: z | |
.string() | |
.min(3, { message: 'Name should have at least 3 characters' }), | |
email: z.string().email({ message: 'Email should be a valid address' }), | |
_id: z.string().optional(), | |
}); | |
export default zSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose from 'mongoose'; | |
const contactSchema = new mongoose.Schema( | |
{ | |
name: { type: String, required: true }, | |
email: { type: String, required: true }, | |
}, | |
{ timestamps: true } | |
); | |
const Contact = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose from 'mongoose'; | |
const MongoConnect = () => { | |
if (mongoose.connections[0].readyState) { | |
console.log('already connected'); | |
return; | |
} | |
mongoose | |
.connect(process.env.MONGO_DB_URI) | |
.then(console.log('connected')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pino from 'pino'; | |
import { createPinoBrowserSend, createWriteStream } from 'pino-logflare'; | |
// create pino-logflare stream | |
const stream = createWriteStream({ | |
apiKey: '----', | |
sourceToken: '----', | |
}); | |
// create pino-logflare browser stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image from 'next/image'; | |
import React, { useState } from 'react'; | |
import { useForm } from 'react-hook-form'; | |
const upload = () => { | |
const [saving, setSaving] = useState(false); | |
const [imageSrc, setImageSrc] = useState(''); | |
const { | |
register, | |
handleSubmit, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; | |
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; | |
export default async function handler(req, res) { | |
const client = new S3Client({ | |
region: process.env.S3_REGION, | |
credentials: { | |
accessKeyId: process.env.S3_ACCESS_KEY, | |
secretAccessKey: process.env.S3_SECRET_KEY, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './globals.css'; | |
import { Inter } from 'next/font/google'; | |
import Script from 'next/script'; | |
import { cookies } from 'next/headers'; | |
import Consent from './components/Consent'; | |
const inter = Inter({ subsets: ['latin'] }); | |
export const metadata = { | |
title: 'Create Next App', |