Compare commits
No commits in common. "4b9797e368c40dbe340e997d46290959be02b17f" and "947f8114d2caf36838769cd2fc34cad2b495a25c" have entirely different histories.
4b9797e368
...
947f8114d2
@ -1 +0,0 @@
|
||||
NEXT_PUBLIC_API_BASE_URL=http://localhost:3000/api/
|
||||
@ -1,13 +1,8 @@
|
||||
'use client';
|
||||
import IconLockDots from '@/components/icon/icon-lock-dots';
|
||||
import IconMail from '@/components/icon/icon-mail';
|
||||
import IconEye from '@/components/icon/icon-eye';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import axios from 'axios';
|
||||
import Cookies from 'universal-cookie';
|
||||
|
||||
const cookies = new Cookies();
|
||||
|
||||
const LoginForm = () => {
|
||||
const router = useRouter();
|
||||
@ -18,9 +13,7 @@ const LoginForm = () => {
|
||||
password: '',
|
||||
});
|
||||
|
||||
// ✅ State for loading and errors
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
// ✅ State for errors
|
||||
const [errors, setErrors] = useState<{ email?: string; password?: string }>({});
|
||||
|
||||
// Generic handler for inputs
|
||||
@ -50,7 +43,7 @@ const LoginForm = () => {
|
||||
return newErrors;
|
||||
};
|
||||
|
||||
const submitForm = async (e: React.FormEvent) => {
|
||||
const submitForm = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const validationErrors = validate();
|
||||
|
||||
@ -59,25 +52,8 @@ const LoginForm = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3000/api/';
|
||||
const response = await axios.post(`${baseUrl}auth/login`, formData);
|
||||
|
||||
if (response.data.success && response.data.data?.token) {
|
||||
cookies.set('token', response.data.data.token, { path: '/' });
|
||||
cookies.set('user', JSON.stringify(response.data.data.user), { path: '/' });
|
||||
router.push('/');
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Login error', error);
|
||||
setErrors({
|
||||
email: error.response?.data?.message || 'Invalid email or password',
|
||||
password: '',
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
console.log('Form Data:', formData);
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
return (
|
||||
@ -109,22 +85,15 @@ const LoginForm = () => {
|
||||
<input
|
||||
id="Password"
|
||||
name="password"
|
||||
type={showPassword ? "text" : "password"}
|
||||
type="password"
|
||||
placeholder="Enter Password"
|
||||
className="form-input ps-10 pe-10 placeholder:text-white-dark"
|
||||
className="form-input ps-10 placeholder:text-white-dark"
|
||||
value={formData.password}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<span className="absolute start-4 top-1/2 -translate-y-1/2">
|
||||
<IconLockDots fill={true} />
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
className={`absolute end-4 top-1/2 -translate-y-1/2 hover:text-black dark:hover:text-white ${showPassword ? 'text-black dark:text-white' : ''}`}
|
||||
>
|
||||
<IconEye />
|
||||
</button>
|
||||
</div>
|
||||
{errors.password && (
|
||||
<p className="text-red-500 text-sm mt-1">{errors.password}</p>
|
||||
@ -134,9 +103,8 @@ const LoginForm = () => {
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-gradient !mt-6 w-full border-0 uppercase shadow-[0_10px_20px_-10px_rgba(67,97,238,0.44)]"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Signing in...' : 'Sign in'}
|
||||
Sign in
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
|
||||
@ -4,7 +4,6 @@ import IconTrashLines from '../icon/icon-trash-lines';
|
||||
import axios from 'axios';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { showMessage } from '@/utils/CommonFunction.utils';
|
||||
import { buildApiUrl } from '@/utils/BaseUrl.utils';
|
||||
|
||||
interface FormValues {
|
||||
year: string;
|
||||
@ -86,7 +85,7 @@ const CreateEventForm: React.FC = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const ImageUpload = await axios.post(buildApiUrl('upload/single'), data, {
|
||||
const ImageUpload = await axios.post(`https://api.tamilculturewaterloo.org/api/upload/single`, data, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data", // important for file upload
|
||||
},
|
||||
@ -100,7 +99,7 @@ const CreateEventForm: React.FC = () => {
|
||||
eventimageurl: ImageUpload?.data?.data?.fullUrl
|
||||
}
|
||||
|
||||
const res = await axios.post(buildApiUrl('events'), createData)
|
||||
const res = await axios.post(`https://api.tamilculturewaterloo.org/api/events`, createData)
|
||||
console.log("res", res)
|
||||
showMessage("Event Created Successfully", "success")
|
||||
router?.push(`/`)
|
||||
|
||||
@ -3,7 +3,6 @@ import React, { useState, ChangeEvent, FormEvent } from 'react';
|
||||
import IconTrashLines from '../icon/icon-trash-lines';
|
||||
import axios from 'axios';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { buildApiUrl } from '@/utils/BaseUrl.utils';
|
||||
|
||||
interface FormErrors {
|
||||
[key: string]: string;
|
||||
@ -62,7 +61,7 @@ const CreateEventGalleryForm: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
formData.append(`files`, file);
|
||||
});
|
||||
|
||||
const uploadRes = await axios.post(buildApiUrl('upload/multiple'), formData)
|
||||
const uploadRes = await axios.post(`https://api.tamilculturewaterloo.org/api/upload/multiple`, formData)
|
||||
console.log("uploadres", uploadRes)
|
||||
const uploadedUrls = uploadRes?.data?.data?.map((image: any) => image?.fullUrl) || [];
|
||||
|
||||
@ -76,7 +75,7 @@ const CreateEventGalleryForm: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
|
||||
// Step 3: Call bulk API
|
||||
await axios.post(
|
||||
buildApiUrl('event-images/bulk'),
|
||||
`https://api.tamilculturewaterloo.org/api/event-images/bulk`,
|
||||
body
|
||||
);
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ import React, { useState, useEffect, ChangeEvent, FormEvent } from 'react';
|
||||
import IconTrashLines from '../icon/icon-trash-lines';
|
||||
import axios from 'axios';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { buildApiUrl } from '@/utils/BaseUrl.utils';
|
||||
|
||||
interface FormValues {
|
||||
year: string;
|
||||
@ -44,7 +43,7 @@ const EditEventForm: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
|
||||
const getEvent = async () => {
|
||||
try {
|
||||
const res = await axios.get(buildApiUrl(`events/${eventId}`));
|
||||
const res = await axios.get(`https://api.tamilculturewaterloo.org/api/events/${eventId}`);
|
||||
const data = res?.data?.data;
|
||||
|
||||
setFormData({
|
||||
@ -125,7 +124,7 @@ const EditEventForm: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
imgFormData.append('file', formData.eventimageurl);
|
||||
|
||||
const uploadRes = await axios.post(
|
||||
buildApiUrl('upload/single'),
|
||||
'https://api.tamilculturewaterloo.org/api/upload/single',
|
||||
imgFormData,
|
||||
{ headers: { 'Content-Type': 'multipart/form-data' } }
|
||||
);
|
||||
@ -141,7 +140,7 @@ const EditEventForm: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
eventimageurl: imageUrl,
|
||||
};
|
||||
|
||||
const res = await axios.put(buildApiUrl(`events/${eventId}`), updatedData, );
|
||||
const res = await axios.put(`https://api.tamilculturewaterloo.org/api/events/${eventId}`, updatedData, );
|
||||
|
||||
console.log('Event updated:', res.data);
|
||||
router.push('/');
|
||||
|
||||
@ -9,7 +9,6 @@ import axios from 'axios';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import IconTrashLines from '../icon/icon-trash-lines';
|
||||
import Swal from 'sweetalert2';
|
||||
import { buildApiUrl } from '@/utils/BaseUrl.utils';
|
||||
|
||||
interface EditEventFormProps {
|
||||
eventId: string | null;
|
||||
@ -30,7 +29,7 @@ const ListOfEventsGallery: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
|
||||
const getEventGallery = async () => {
|
||||
try {
|
||||
const res = await axios.get(buildApiUrl(`event-images/event/${eventId}`));
|
||||
const res = await axios.get(`https://api.tamilculturewaterloo.org/api/event-images/event/${eventId}`);
|
||||
const formatted = res.data?.data?.map((img: any) => ({
|
||||
id: img.id, // ensure ID is preserved for deletion
|
||||
src: img.imageurl,
|
||||
@ -59,7 +58,7 @@ const ListOfEventsGallery: React.FC<EditEventFormProps> = ({ eventId }) => {
|
||||
}).then(async (result) => {
|
||||
if (result.isConfirmed) {
|
||||
try {
|
||||
await axios.delete(buildApiUrl(`event-images/${item.id}`));
|
||||
await axios.delete(`https://api.tamilculturewaterloo.org/api/event-images/${item.id}`);
|
||||
Swal.fire({
|
||||
title: 'Deleted!',
|
||||
text: 'Your file has been deleted.',
|
||||
|
||||
@ -7,7 +7,6 @@ import IconTrashLines from '../icon/icon-trash-lines';
|
||||
import IconPencil from '../icon/icon-pencil';
|
||||
import Swal from 'sweetalert2';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { buildApiUrl } from '@/utils/BaseUrl.utils';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Knowledge Base',
|
||||
@ -24,7 +23,7 @@ const ListOfEvents = () => {
|
||||
|
||||
const getEvents = async () => {
|
||||
try {
|
||||
const eventRes: any = await axios?.get(buildApiUrl('events'))
|
||||
const eventRes: any = await axios?.get(`https://api.tamilculturewaterloo.org/api/events`)
|
||||
console.log("eventRes", eventRes)
|
||||
setEvents(eventRes?.data?.data)
|
||||
} catch (error) {
|
||||
@ -62,7 +61,7 @@ const ListOfEvents = () => {
|
||||
}).then(async (result) => {
|
||||
if (result.isConfirmed) {
|
||||
try {
|
||||
await axios.delete(buildApiUrl(`events/${event.id}`));
|
||||
await axios.delete(`https://api.tamilculturewaterloo.org/api/events/${event.id}`);
|
||||
Swal.fire({
|
||||
title: 'Deleted!',
|
||||
text: 'Your file has been deleted.',
|
||||
|
||||
@ -1,13 +1 @@
|
||||
const DEFAULT_BASE_URL = 'https://api.tamilculturewaterloo.org/api/';
|
||||
|
||||
const configuredBaseUrl =
|
||||
typeof process !== 'undefined' && process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
? process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
: DEFAULT_BASE_URL;
|
||||
|
||||
export const Baseurl = configuredBaseUrl.endsWith('/') ? configuredBaseUrl : `${configuredBaseUrl}/`;
|
||||
|
||||
export const buildApiUrl = (path) => {
|
||||
const normalizedPath = String(path).replace(/^\/+/, '');
|
||||
return `${Baseurl}${normalizedPath}`;
|
||||
};
|
||||
export const Baseurl = "https://api.tamilculturewaterloo.org/api/"
|
||||
Loading…
x
Reference in New Issue
Block a user