Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Migrating to laravel
  • Loading branch information
NaysKutzu committed Dec 21, 2024
1 parent 1eb78c7 commit 481fc5f
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 54 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@tanstack/vue-table": "^8.20.5",
"@types/js-cookie": "^3.0.6",
"@vueuse/sound": "^2.0.1",
"axios": "^1.7.9",
"date-fns": "^4.1.0",
"js-cookie": "^3.0.5",
"lucide-vue-next": "^0.468.0",
Expand Down
165 changes: 111 additions & 54 deletions frontend/src/components/client/Dashboard/Account/Activities.vue
Original file line number Diff line number Diff line change
@@ -1,69 +1,126 @@
<script setup lang="ts">
import LayoutAccount from './Layout.vue';
import TableTanstack from '@/components/client/ui/Table/TableTanstack.vue';
import { format } from 'date-fns';
import { ref, onMounted, onErrorCaptured } from 'vue'
import axios from 'axios'
import { format } from 'date-fns'
import LayoutAccount from './Layout.vue'
const Activities = [
{
action: 'Login',
description: 'User logged in',
ip_address: '127.0.0.1',
date: '2023-10-01',
},
{
action: 'Logout',
description: 'User logged out',
ip_address: '127.0.0.1',
date: '2023-10-01',
},
{
action: 'Login',
description: 'User logged in',
ip_address: '127.0.0.1',
date: '2023-10-01',
},
];
const columnsActivities = [
{
accessorKey: 'action',
header: 'Action',
},
{
accessorKey: 'description',
header: 'Description',
},
{
accessorKey: 'ip_address',
header: 'Ip Address',
},
{
accessorKey: 'date',
header: 'Created',
cell: (info: { getValue: () => string | number | Date }) => format(new Date(info.getValue()), 'MMM d, yyyy'),
},
];
interface Activity {
id: number
user: string
action: string
ip_address: string
deleted: string
locked: string
date: string
}
interface ActivityResponse {
code: number
error: null | string
message: string
success: boolean
activities: Activity[]
}
const activities = ref<Activity[]>([])
const loading = ref(true)
const error = ref<string | null>(null)
const fetchActivities = async () => {
try {
console.log('Fetching activities...')
const response = await axios.get<ActivityResponse>('/api/user/session/activities')
console.log('Response received:', response.data)
if (response.data.success) {
activities.value = response.data.activities
console.log('Activities loaded:', activities.value)
} else {
throw new Error(response.data.error || 'Failed to fetch activities')
}
} catch (err) {
console.error('Error fetching activities:', err)
error.value = err instanceof Error ? err.message : 'An unknown error occurred'
} finally {
loading.value = false
}
}
onMounted(() => {
console.log('Component mounted')
fetchActivities()
})
onErrorCaptured((err) => {
console.error('Error captured:', err)
error.value = 'An unexpected error occurred'
return false
})
const columns = [
{ key: 'id', title: 'ID' },
{ key: 'action', title: 'Action' },
{ key: 'ip_address', title: 'IP Address' },
{ key: 'date', title: 'Date' },
{ key: 'deleted', title: 'Deleted' },
{ key: 'locked', title: 'Locked' },
]
const formatDate = (date: string) => format(new Date(date), 'MMM d, yyyy HH:mm:ss')
</script>
<template>
<!-- User Info -->
<LayoutAccount />

<div>
<div class="overflow-x-auto">
<TableTanstack :data="Activities" :columns="columnsActivities" tableName="Activities" />
<template>
<LayoutAccount>
<div class="p-4">
<h2 class="text-2xl font-bold mb-4">User Activities</h2>
<div v-if="loading" class="text-center py-4">
<div class="inline-block animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-gray-900"></div>
<p class="mt-2">Loading activities...</p>
</div>
<div v-else-if="error" class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded" role="alert">
<p>{{ error }}</p>
</div>
<div v-else-if="activities.length === 0" class="text-center py-4">
<p>No activities found.</p>
</div>
<div v-else class="overflow-x-auto">
<table class="min-w-full bg-white border border-gray-300">
<thead>
<tr>
<th v-for="column in columns" :key="column.key"
class="px-6 py-3 bg-gray-100 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
{{ column.title }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="activity in activities" :key="activity.id" class="border-b border-gray-200">
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">{{ activity.id }}
</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-900">{{ activity.action
}}</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">{{
activity.ip_address }}</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">{{
formatDate(activity.date) }}</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">{{ activity.deleted
}}</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">{{ activity.locked
}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</LayoutAccount>
</template>

<style scoped>
/* Hide scrollbar for Chrome, Safari and Opera */
.overflow-x-auto::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.overflow-x-auto {
-ms-overflow-style: none;
/* IE and Edge */
scrollbar-width: none;
/* Firefox */
}
</style>
</style>
49 changes: 49 additions & 0 deletions frontend/src/components/client/Dashboard/Account/ActivityTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { format } from 'date-fns'
interface Activity {
id: number
user: string
action: string
ip_address: string
deleted: string
locked: string
date: string
}
defineProps<{
activities: Activity[]
}>()
</script>

<template>
<div class="overflow-x-auto bg-gray-900 rounded-lg shadow">
<table class="min-w-full divide-y divide-gray-800">
<thead class="bg-gray-800">
<tr>
<th scope="col"
class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">
Action
</th>
<th scope="col"
class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">
IP Address
</th>
<th scope="col"
class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">
Date
</th>
</tr>
</thead>
<tbody class="bg-gray-900 divide-y divide-gray-800">
<tr v-for="activity in activities" :key="activity.id" class="hover:bg-gray-800 transition-colors">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">{{ activity.action }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">{{ activity.ip_address }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">
{{ format(new Date(activity.date), 'MMM d, yyyy HH:mm:ss') }}
</td>
</tr>
</tbody>
</table>
</div>
</template>
16 changes: 16 additions & 0 deletions frontend/src/mythicalclient/Activities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Activities {
/**
* Get the activities for the current session
*
* @returns The response from the server
*/
public static async get() {
const response = await fetch('/api/user/session/activities', {
method: 'GET',
});
const data = await response.json();
return data.activities;
}
}

export default Activities;
57 changes: 57 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,11 @@ argparse@^2.0.1:
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

autoprefixer@^10.4.20:
version "10.4.20"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.20.tgz#5caec14d43976ef42e32dcb4bd62878e96be5b3b"
Expand All @@ -1141,6 +1146,15 @@ autoprefixer@^10.4.20:
picocolors "^1.0.1"
postcss-value-parser "^4.2.0"

axios@^1.7.9:
version "1.7.9"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.9.tgz#d7d071380c132a24accda1b2cfc1535b79ec650a"
integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down Expand Up @@ -1273,6 +1287,13 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"

commander@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
Expand Down Expand Up @@ -1364,6 +1385,11 @@ define-lazy-prop@^3.0.0:
resolved "https://registry.yarnpkg.com/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz#dbb19adfb746d7fc6d734a06b72f4a00d021255f"
integrity sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

didyoumean@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.2.tgz#989346ffe9e839b4555ecf5666edea0d3e8ad037"
Expand Down Expand Up @@ -1694,6 +1720,11 @@ flatted@^3.2.9:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.2.tgz#adba1448a9841bec72b42c532ea23dbbedef1a27"
integrity sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA==

follow-redirects@^1.15.6:
version "1.15.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==

foreground-child@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/foreground-child/-/foreground-child-3.3.0.tgz#0ac8644c06e431439f8561db8ecf29a7b5519c77"
Expand All @@ -1702,6 +1733,15 @@ foreground-child@^3.1.0:
cross-spawn "^7.0.0"
signal-exit "^4.0.1"

form-data@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48"
integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

fraction.js@^4.3.7:
version "4.3.7"
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.3.7.tgz#06ca0085157e42fda7f9e726e79fefc4068840f7"
Expand Down Expand Up @@ -2115,6 +2155,18 @@ micromatch@^4.0.4, micromatch@^4.0.8:
braces "^3.0.3"
picomatch "^2.3.1"

mime-db@1.52.0:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

mime-types@^2.1.12:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
dependencies:
mime-db "1.52.0"

minimatch@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
Expand Down Expand Up @@ -2473,6 +2525,11 @@ pretty-ms@^9.0.0:
dependencies:
parse-ms "^4.0.0"

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

punycode@^2.1.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
Expand Down

0 comments on commit 481fc5f

Please sign in to comment.