ok
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import { createClerks } from '../helpers/userHelpers'; // Adjust the import path as needed
|
||||
import { createCafe } from '../helpers/cafeHelpers'; // Adjust the import path as needed
|
||||
|
||||
const CreateClerk = ({ shopId }) => {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [message, setMessage] = useState('');
|
||||
|
||||
@@ -13,16 +12,16 @@ const CreateClerk = ({ shopId }) => {
|
||||
setMessage('');
|
||||
|
||||
// Basic validation
|
||||
if (!username || !password) {
|
||||
setMessage('Username and password are required');
|
||||
if (!name) {
|
||||
setMessage('name is required');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const create = await createClerks(shopId, username, password);
|
||||
const create = await createCafe(name);
|
||||
|
||||
if (create) setMessage('Clerk created successfully');
|
||||
if (create) setMessage('Cafe created successfully');
|
||||
else setMessage('Failed to create clerk');
|
||||
} catch (error) {
|
||||
setMessage('Error creating clerk');
|
||||
@@ -37,16 +36,9 @@ const CreateClerk = ({ shopId }) => {
|
||||
<form onSubmit={handleSubmit} style={styles.form}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Cafe name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
<button type="submit" style={styles.button} disabled={loading}>
|
||||
|
||||
Reference in New Issue
Block a user