Skip to content

Commit

Permalink
Merge pull request #10 from launchdarkly-labs/tony_remove_db
Browse files Browse the repository at this point in the history
Tony remove db
  • Loading branch information
tonytrinh3 authored May 7, 2024
2 parents 7358a4c + cce51ab commit c2206a7
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 603 deletions.
69 changes: 22 additions & 47 deletions components/personacontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,33 @@ export const PersonaContext = createContext(null);

export const PersonaProvider = ({ children }) => {
const [personas, setPersonas] = useState([]);
const [error, setError] = useState(null);

const getPersonas = async () => {
fetch("/api/personas?personaToQuery=all")
.then((response) => response.json())
.then((data) => {
setPersonas(data);
})
.catch((error) => {
setError(error.message);
});
}

const addPersona = async (newPersona) => {
fetch('/api/personas', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
const getPersonas = () => {
const starterPersonas = [
{
personaname: "Cody",
personatype: "Standard User",
personaimage: "standard.jpg",
personaemail: "[email protected]",
},
body: JSON.stringify(newPersona),
})
.then(response => response.json())
.then(data => {
if (data && data.error) {
setError(data.error);
} else {
setPersonas(prevPersonas => [...prevPersonas, data]);
}
})
.catch(error => {
setError('Failed to create new persona. Please try again.');
});
};

const deleteAllPersonas = async () => {
fetch('/api/personas', {
method: 'DELETE',
})
.then(response => {
if (response.ok) {
setPersonas([]);
} else {
throw new Error('Failed to delete all personas');
}
})
.catch(error => {
setError(error.message);
});
{
personaname: "Alysha",
personatype: "Beta User",
personaimage: "beta.png",
personaemail: "[email protected]",
},
{
personaname: "Jenn",
personatype: "Developer",
personaimage: "woman.png",
personaemail: "[email protected]",
},
];
setPersonas(starterPersonas);
};

return (
<PersonaContext.Provider value={{ personas, error, addPersona, deleteAllPersonas, getPersonas }}>
<PersonaContext.Provider value={{ personas, getPersonas }}>
{children}
</PersonaContext.Provider>
);
Expand Down
36 changes: 5 additions & 31 deletions components/ui/logincomponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function LoginComponent({ isLoggedIn, setIsLoggedIn, loginUser, name }: L
const marketButtonColorClass = "bg-gradient-to-r from-marketblue text-black to-marketgreen text-black";

const [newPersona, setNewPersona] = useState({ name: '', type: '', image: '', email: '' });
const { personas, addPersona, deleteAllPersonas, getPersonas } = useContext(PersonaContext);
const { personas, getPersonas } = useContext(PersonaContext);
const [isAddUserDropdownOpen, setIsAddUserDropdownOpen] = useState(false);
const [submitError, setSubmitError] = useState(null);
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -41,24 +41,6 @@ export function LoginComponent({ isLoggedIn, setIsLoggedIn, loginUser, name }: L
getPersonas();
}, [isLoading]);

const handleSubmitNewPersona = () => {
const emailExists = personas.some(persona => persona.personaEmail === newPersona.email);
if (emailExists) {
setSubmitError('A persona with this email already exists.');
return;
}
setIsLoading(true);
addPersona(newPersona)
.then(() => {
setIsAddUserDropdownOpen(false);
setIsLoading(false);
getPersonas();
})
.catch(error => {
setSubmitError('Failed to create new persona. Please try again.');
setIsLoading(false);
})
};

const showBackButton = () => {
setIsAddUserDropdownOpen(false);
Expand All @@ -85,14 +67,6 @@ export function LoginComponent({ isLoggedIn, setIsLoggedIn, loginUser, name }: L
loginUser(name, email);
};

const handleDeleteAllPersonas = () => {
setIsLoading(true);
deleteAllPersonas()
.then(() => {
getPersonas();
setIsLoading(false);
})
}

const handleSetActive = (personaname, personaemail) => {
setActiveElement(personaname);
Expand Down Expand Up @@ -159,8 +133,8 @@ export function LoginComponent({ isLoggedIn, setIsLoggedIn, loginUser, name }: L
) : (
<div className="overflow-y-auto h-64">
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4 justify-items-center mb-4 pt-6">
{personas.map((item: Persona) => (
<div className="flex flex-col items-center" key={item.id}>
{personas.map((item: Persona, index: number) => (
<div className="flex flex-col items-center" key={index}>
<img
src={item.personaimage}
className={`w-24 rounded-full mb-4 ${activeElement === item.personaname ? 'border-4 border-black' : ''}`}
Expand Down Expand Up @@ -228,7 +202,7 @@ export function LoginComponent({ isLoggedIn, setIsLoggedIn, loginUser, name }: L
))}
</div>
</div>
<Button onClick={handleSubmitNewPersona} className={`mb-2 w-full h-full mx-auto font-audimat mt-2 rounded-none text-xl ${marketButtonColorClass}`}>
<Button className={`mb-2 w-full h-full mx-auto font-audimat mt-2 rounded-none text-xl ${marketButtonColorClass}`}>
Submit
</Button>

Expand All @@ -250,7 +224,7 @@ export function LoginComponent({ isLoggedIn, setIsLoggedIn, loginUser, name }: L
Add New User
</Button>

<Button onClick={handleDeleteAllPersonas} className={`flex-grow ml-1 w-1/8 font-audimat rounded-none text-lg h-full ${marketButtonColorClass}`}>
<Button className={`flex-grow ml-1 w-1/8 font-audimat rounded-none text-lg h-full ${marketButtonColorClass}`}>
&#x21bb;
</Button>
</div>
Expand Down
66 changes: 63 additions & 3 deletions components/ui/marketcomponents/stores/MacroCenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,69 @@ export function MacroCenter({
const [inventory, setInventory] = useState([]);

useEffect(() => {
fetch("/api/storeInventory?storename=macrocenter")
.then((response) => response.json())
.then((data) => setInventory(data));
const data = [
{
"id": 11,
"vendor": "macrocenter",
"item": "High-Performance Graphics Card - 8GB",
"cost": "699.99"
},
{
"id": 12,
"vendor": "macrocenter",
"item": "Gaming Motherboard - RGB Lighting",
"cost": "259.99"
},
{
"id": 13,
"vendor": "macrocenter",
"item": "Solid State Drive (SSD) - 1TB",
"cost": "129.99"
},
{
"id": 14,
"vendor": "macrocenter",
"item": "DDR4 RAM - 16GB Kit (2x8GB)",
"cost": "89.99"
},
{
"id": 15,
"vendor": "macrocenter",
"item": "Modular Power Supply - 750W",
"cost": "119.99"
},
{
"id": 16,
"vendor": "macrocenter",
"item": "CPU Cooler - Liquid Cooling System",
"cost": "139.99"
},
{
"id": 17,
"vendor": "macrocenter",
"item": "Full-Tower PC Case - Tempered Glass",
"cost": "199.99"
},
{
"id": 18,
"vendor": "macrocenter",
"item": "Wireless Gaming Keyboard and Mouse Combo",
"cost": "99.99"
},
{
"id": 19,
"vendor": "macrocenter",
"item": "27-inch Gaming Monitor - 144Hz",
"cost": "329.99"
},
{
"id": 20,
"vendor": "macrocenter",
"item": "Internal Sound Card - 7.1 Surround",
"cost": "79.99"
}
];
setInventory(data);
}, []);

return (
Expand Down
67 changes: 64 additions & 3 deletions components/ui/marketcomponents/stores/TheBoominBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,70 @@ export function TheBoominBox({
const [inventory, setInventory] = useState([]);

useEffect(() => {
fetch("/api/storeInventory?storename=boominbox")
.then((response) => response.json())
.then((data) => setInventory(data));

const data = [
{
"id": 21,
"vendor": "boominbox",
"item": "VR Headset - Advanced Model",
"cost": "499.99"
},
{
"id": 22,
"vendor": "boominbox",
"item": "Bluetooth Noise-Canceling Headphones",
"cost": "299.99"
},
{
"id": 23,
"vendor": "boominbox",
"item": "Wireless Earbuds - Waterproof Edition",
"cost": "159.99"
},
{
"id": 24,
"vendor": "boominbox",
"item": "High-Fidelity Turntable",
"cost": "349.99"
},
{
"id": 25,
"vendor": "boominbox",
"item": "Portable Bluetooth Speaker - Rugged Design",
"cost": "119.99"
},
{
"id": 26,
"vendor": "boominbox",
"item": "Studio Monitor Speakers (Pair)",
"cost": "499.99"
},
{
"id": 27,
"vendor": "boominbox",
"item": "Multi-Channel Home Theater System",
"cost": "999.99"
},
{
"id": 28,
"vendor": "boominbox",
"item": "Digital Audio Interface - Pro Series",
"cost": "229.99"
},
{
"id": 29,
"vendor": "boominbox",
"item": "Smart Home Sound System with Voice Control",
"cost": "399.99"
},
{
"id": 30,
"vendor": "boominbox",
"item": "Professional DJ Mixer",
"cost": "699.99"
}
]
setInventory(data);
}, []);

return (
Expand Down
66 changes: 63 additions & 3 deletions components/ui/marketcomponents/stores/vrgalaxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,69 @@ export function VRgalaxy({


useEffect(() => {
fetch("/api/storeInventory?storename=vrgalaxy")
.then((response) => response.json())
.then((data) => setInventory(data));
const data = [
{
"id": 1,
"vendor": "vrgalaxy",
"item": "VR Headset - Advanced Model",
"cost": "499.99"
},
{
"id": 2,
"vendor": "vrgalaxy",
"item": "Wireless VR Controllers (Pair)",
"cost": "119.99"
},
{
"id": 3,
"vendor": "vrgalaxy",
"item": "VR Treadmill for Immersive Movement",
"cost": "899.99"
},
{
"id": 4,
"vendor": "vrgalaxy",
"item": "Haptic Feedback Gloves",
"cost": "259.99"
},
{
"id": 5,
"vendor": "vrgalaxy",
"item": "Virtual Reality Game - Space Adventure",
"cost": "59.99"
},
{
"id": 6,
"vendor": "vrgalaxy",
"item": "VR Headset Cleaning Kit",
"cost": "29.99"
},
{
"id": 7,
"vendor": "vrgalaxy",
"item": "360° VR Camera",
"cost": "349.99"
},
{
"id": 8,
"vendor": "vrgalaxy",
"item": "Virtual Reality Development Software",
"cost": "199.99"
},
{
"id": 9,
"vendor": "vrgalaxy",
"item": "Adjustable VR Headset Stand",
"cost": "39.99"
},
{
"id": 10,
"vendor": "vrgalaxy",
"item": "Virtual Reality Experience Ticket - Underwater World",
"cost": "14.99"
}
];
setInventory(data);
}, []);

async function storeOpened() {
Expand Down
Loading

0 comments on commit c2206a7

Please sign in to comment.