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