Skip to content

Commit

Permalink
can add admins from website
Browse files Browse the repository at this point in the history
  • Loading branch information
meganleongg committed Apr 30, 2024
1 parent 8d2b455 commit 8dc59d1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
7 changes: 4 additions & 3 deletions admin-portal-frontend/src/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import InviteAdmin from '../invite-admin';


export default function Home() {


return (
<div className="flex items-center justify-center">
logged in!
</div>
<><div className="flex items-center justify-center mb-2">
Success! Logged in!
</div><InviteAdmin /></>

);
}
58 changes: 58 additions & 0 deletions admin-portal-frontend/src/app/invite-admin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use client";

import React, { useState } from 'react';
import { doc, setDoc, getFirestore } from 'firebase/firestore';

const InviteAdmin = () => {
const [email, setEmail] = useState('');
const [status, setStatus] = useState('');
const db = getFirestore();

const handleInvite = async (e: any) => {
e.preventDefault();
const inviteRef = doc(db, 'invitations', email);

try {
await setDoc(inviteRef, { invited: true });
setStatus('Invitation sent successfully.');
setEmail('');
} catch (error: any) {
setStatus(`Failed to send invitation: ${error.message}`);
}
};



return (
<div className="flex items-center justify-center">
<form onSubmit={handleInvite} className="flex flex-col items-center">
<input
className="mb-2 p-2 border w-full rounded border-gray-400"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter email to invite"
required
/>
<button
type="submit"
style={{
backgroundColor: '#00629B',
color: 'white',
border: 'none',
borderRadius: '4px',
padding: '7px 14px',
cursor: 'pointer',
}}
className="hover:bg-blue-700 transition-colors"
>
Add Admin
</button>
</form>
{status && <p>{status}</p>}
</div>
);

};

export default InviteAdmin;

0 comments on commit 8dc59d1

Please sign in to comment.