Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ NEXT_PUBLIC_DOCS_BASE_URL='http://localhost:3002'
NEXT_PUBLIC_LANDING_BASE_URL='http://localhost:3000'
NEXT_PUBLIC_LEARN_BASE_URL='http://localhost:3003'
NEXT_PUBLIC_SCOUT_BASE_URL='http://localhost:3004'
NEXT_PUBLIC_ATTENDANCE_BASE_URL='http://localhost:3005'

NODE_ENV='development'
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ jobs:
echo "NEXT_PUBLIC_LANDING_BASE_URL=${NEXT_PUBLIC_LANDING_BASE_URL}"
echo "NEXT_PUBLIC_LEARN_BASE_URL=${NEXT_PUBLIC_LEARN_BASE_URL}"
echo "NEXT_PUBLIC_SCOUT_BASE_URL=${NEXT_PUBLIC_SCOUT_BASE_URL}"
echo "NEXT_PUBLIC_ATTENDANCE_BASE_URL=${NEXT_PUBLIC_ATTENDANCE_BASE_URL}"
echo "CRON_SECURITY_KEY=${CRON_SECRET_KEY}"
echo "NODE_TLS_REJECT_UNAUTHORIZED=0"
} > "apps/$APP/.env"
cp "apps/$APP/.env" "apps/$APP/.env.production"
Expand All @@ -129,6 +131,8 @@ jobs:
NEXT_PUBLIC_LANDING_BASE_URL: ${{ secrets.NEXT_PUBLIC_LANDING_BASE_URL }}
NEXT_PUBLIC_LEARN_BASE_URL: ${{ secrets.NEXT_PUBLIC_LEARN_BASE_URL }}
NEXT_PUBLIC_SCOUT_BASE_URL: ${{ secrets.NEXT_PUBLIC_SCOUT_BASE_URL }}
NEXT_PUBLIC_ATTENDANCE_BASE_URL: ${{ secrets.NEXT_PUBLIC_ATTENDANCE_BASE_URL }}
CRON_SECRET_KEY: ${{ secrets.CRON_SECRET_KEY }}

- name: Turbo prebuild all deployable apps
run: |
Expand Down Expand Up @@ -232,6 +236,8 @@ jobs:
webhook_key: WEBHOOK_URL_SCOUT
- app: docs
webhook_key: WEBHOOK_URL_DOCS
- app: attendance
webhook_key: WEBHOOK_URL_ATTENDANCE

steps:
- name: Checkout
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
- name: Generate environment files
run: |
set -euo pipefail
for APP in auth landing learn scout nitro-api; do
for APP in auth landing learn scout nitro-api attendance; do
mkdir -p "apps/$APP"
{
echo "NODE_ENV=${NODE_ENV}"
Expand All @@ -121,6 +121,8 @@ jobs:
echo "NEXT_PUBLIC_LANDING_BASE_URL=${NEXT_PUBLIC_LANDING_BASE_URL}"
echo "NEXT_PUBLIC_LEARN_BASE_URL=${NEXT_PUBLIC_LEARN_BASE_URL}"
echo "NEXT_PUBLIC_SCOUT_BASE_URL=${NEXT_PUBLIC_SCOUT_BASE_URL}"
echo "NEXT_PUBLIC_ATTENDANCE_BASE_URL=${NEXT_PUBLIC_ATTENDANCE_BASE_URL}"
echo "CRON_SECURITY_KEY=${CRON_SECURITY_KEY}"
echo "NODE_TLS_REJECT_UNAUTHORIZED=0"
} > "apps/$APP/.env"
cp "apps/$APP/.env" "apps/$APP/.env.production"
Expand All @@ -138,10 +140,12 @@ jobs:
NEXT_PUBLIC_LANDING_BASE_URL: ${{ secrets.NEXT_PUBLIC_LANDING_BASE_URL }}
NEXT_PUBLIC_LEARN_BASE_URL: ${{ secrets.NEXT_PUBLIC_LEARN_BASE_URL }}
NEXT_PUBLIC_SCOUT_BASE_URL: ${{ secrets.NEXT_PUBLIC_SCOUT_BASE_URL }}
NEXT_PUBLIC_ATTENDANCE_BASE_URL: ${{ secrets.NEXT_PUBLIC_ATTENDANCE_BASE_URL }}
CRON_SECURITY_KEY: ${{ secrets.CRON_SECURITY_KEY }}

- name: Turbo prebuild all deployable apps
run: |
pnpm turbo run build --filter=./apps/auth --filter=./apps/landing --filter=./apps/learn --filter=./apps/scout --filter=./apps/docs --filter=./apps/nitro-api
pnpm turbo run build --filter=./apps/auth --filter=./apps/landing --filter=./apps/learn --filter=./apps/scout --filter=./apps/docs --filter=./apps/nitro-api --filter=./apps/attendance

- name: List built artifacts
run: |
Expand All @@ -151,12 +155,13 @@ jobs:
ls -1 apps/scout/.next || true
ls -1 apps/docs/.next || true
ls -1 apps/nitro-api/.output || true
ls -1 apps/attendance/.next || true

- name: Package build artifacts
run: |
set -euo pipefail
mkdir -p dist-artifacts
for APP in auth landing learn scout docs; do
for APP in auth landing learn scout docs attendance; do
if [ -d "apps/$APP/.next" ]; then
(cd apps/$APP && tar -czf "../../dist-artifacts/next-${APP}${ARTIFACT_SUFFIX}.tgz" .next $( [ -f .env ] && echo .env ) $( [ -f .env.production ] && echo .env.production ))
echo "Packaged next-${APP}${ARTIFACT_SUFFIX}.tgz"
Expand Down Expand Up @@ -222,6 +227,14 @@ jobs:
if-no-files-found: error
retention-days: 3

- name: Upload artifact attendance
uses: actions/upload-artifact@v4
with:
name: next-attendance${{ env.ARTIFACT_SUFFIX }}
path: dist-artifacts/next-attendance${{ env.ARTIFACT_SUFFIX }}.tgz
if-no-files-found: error
retention-days: 3

build-next:
if: github.event.pull_request.base.ref != 'production' || github.event.pull_request.head.ref != 'staging'
name: Build Next.js images (prebuilt, no push)
Expand All @@ -236,6 +249,7 @@ jobs:
- app: learn
- app: scout
- app: docs
- app: attendance
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
46 changes: 46 additions & 0 deletions apps/attendance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# OpenNext
/.open-next

# wrangler files
.wrangler
.dev.vars*
!.dev.vars.example
.env*
!.env.example
102 changes: 102 additions & 0 deletions apps/attendance/app/_actions/server-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"use server";

import { auth } from "@spike/auth";
import { attendance, db } from "@spike/db";
import { eq, and, isNull } from "drizzle-orm";
import { headers } from "next/headers";

export async function logAction(action: string, userId: string) {
const today = new Date().toISOString().split("T")[0];

if (action === "check-in") {
// Always create a new record on check-in
await db.insert(attendance).values({
userId,
date: today,
status: "present",
checkInTime: new Date(),
} as any);
return;
}

if (action === "check-out") {
// Find the latest (open) record for today without a check-out time
const openRecord = await db
.select()
.from(attendance)
.where(
and(
eq(attendance.userId, userId),
eq(attendance.date, today),
isNull(attendance.checkOutTime),
),
)
.limit(1);

if (openRecord.length > 0) {
await db
.update(attendance)
.set({
checkOutTime: new Date(),
updatedAt: new Date(),
} as any)
.where(eq(attendance.id, openRecord[0].id));
}

return;
}
}

export async function getStatus(
userId: string,
): Promise<"checked-in" | "checked-out"> {
const today = new Date().toISOString().split("T")[0];

// Any open (no checkOutTime) record today means user is currently checked in
const openRecord = await db
.select()
.from(attendance)
.where(
and(
eq(attendance.userId, userId),
eq(attendance.date, today),
isNull(attendance.checkOutTime),
),
)
.limit(1);

if (openRecord.length > 0) {
return "checked-in";
}

return "checked-out";
}

export async function getCheckedInTime(userId: string): Promise<Date | null> {
const today = new Date().toISOString().split("T")[0];

// Get the current open session (no checkOutTime) for today
const openRecord = await db
.select()
.from(attendance)
.where(
and(
eq(attendance.userId, userId),
eq(attendance.date, today),
isNull(attendance.checkOutTime),
),
)
.limit(1);

if (openRecord.length === 0 || !openRecord[0].checkInTime) {
return null;
}

return openRecord[0].checkInTime;
}

export async function signOut() {
await auth.api.signOut({
headers: await headers(),
});
}
63 changes: 63 additions & 0 deletions apps/attendance/app/_components/attendance-status.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Button } from "@spike/ui/button";
import { Card, CardContent } from "@spike/ui/card";
import { Clock } from "lucide-react";
import { TimeDisplay } from "./time-display";

interface AttendanceStatusProps {
isCheckedIn: boolean;
checkInTime: string | null;
checkOutTime: string | null;
onCheckInOut: (status: string) => void;
loading?: boolean;
}

export function AttendanceStatus({
isCheckedIn,
checkInTime,
checkOutTime,
onCheckInOut,
loading = false,
}: AttendanceStatusProps) {
return (
<Card>
<CardContent className="pt-6">
<div className="text-center space-y-4">
<div className="mx-auto w-20 h-20 bg-gradient-to-br from-green-400 to-blue-500 rounded-full flex items-center justify-center">
<Clock className="w-10 h-10 text-white" />
</div>

<div>
<h2 className="text-2xl font-bold text-gray-800">
{isCheckedIn ? "Checked In" : "Not Checked In"}
</h2>
<p className="text-gray-600">
{isCheckedIn
? "You are currently in session"
: "Ready to start your session?"}
</p>
</div>

<TimeDisplay checkInTime={checkInTime} checkOutTime={checkOutTime} />

<Button
onClick={() => onCheckInOut(isCheckedIn ? "check-out" : "check-in")}
disabled={loading}
className={`w-full text-lg py-6 ${
isCheckedIn
? "bg-red-500 hover:bg-red-600 text-white"
: "bg-green-500 hover:bg-green-600 text-white"
}`}
>
{loading
? isCheckedIn
? "Checking Out..."
: "Checking In..."
: isCheckedIn
? "Check Out"
: "Check In"}
</Button>
</div>
</CardContent>
</Card>
);
}
78 changes: 78 additions & 0 deletions apps/attendance/app/_components/attendance-tracker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"use client";

import { useState } from "react";
import { AttendanceStatus } from "./attendance-status";
import { StatusIndicator } from "./status-indicator";
import { getCurrentDate } from "~/lib/date-helper";
import { UserHeader } from "./user-header";
import { asUrl } from "@spike/config/paths.config";
import sharedEnv from "@spike/env/env.shared";
import { redirect } from "next/navigation";
import { logAction } from "~/_actions/server-actions";
import { ViewAdminDashboard } from "./view-admin-dashboard";

export default function AttendanceTracker({
session,
isCheckedIn: initialCheckedIn,
checkInTime: initialCheckInTime,
}: {
session?: any;
isCheckedIn: boolean;
checkInTime?: Date;
}) {
const [isCheckedIn, setIsCheckedIn] = useState(initialCheckedIn);
const [checkInTime, setCheckInTime] = useState<Date | undefined>(
initialCheckInTime,
);
const [checkOutTime, setCheckOutTime] = useState<string | null>(null);
const [loading, setLoading] = useState(false);

if (!session) {
redirect(
asUrl("auth", "login") + "?redirectUrl=" + sharedEnv.ATTENDANCE_BASE_URL,
);
}

const formatTime = (date: Date) => {
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
};

const checkInOutHandler = async (status: string) => {
if (!session) return;
setLoading(true);
await logAction(status, session.user.id);
if (status === "check-in") {
setIsCheckedIn(true);
setCheckInTime(new Date());
setCheckOutTime(null);
} else {
setIsCheckedIn(false);
setCheckOutTime(formatTime(new Date()));
setCheckInTime(undefined);
}
setLoading(false);
};

return (
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 p-4">
<div className="max-w-md mx-auto space-y-6">
<UserHeader
userName={session.user.name}
currentDate={getCurrentDate()}
/>

<AttendanceStatus
isCheckedIn={isCheckedIn}
checkInTime={checkInTime ? formatTime(checkInTime) : null}
checkOutTime={checkOutTime}
onCheckInOut={checkInOutHandler}
loading={loading}
/>

<StatusIndicator isCheckedIn={isCheckedIn} />

<ViewAdminDashboard hasAccess={session.user.role === "admin"} />
</div>
</div>
);
}
Loading