Skip to content

Commit f6e5324

Browse files
committed
phase 6 done
1 parent 45c14a9 commit f6e5324

148 files changed

Lines changed: 535 additions & 286 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/codebility/actions/settings/services.ts‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { createClientServerComponent } from "@/utils/supabase/server";
44
import { Codev } from "@/types/home/codev";
5+
import { z } from "zod";
56

67
export interface RealProject {
78
id: string;
@@ -110,4 +111,90 @@ export async function getCodevProfiles() {
110111
console.error('❌ Error fetching codev profiles:', error);
111112
return { data: [], error: 'Failed to fetch codev profiles' };
112113
}
114+
}
115+
116+
const serviceWriteSchema = z.object({
117+
name: z.string().min(1, "Service name is required"),
118+
description: z.string().min(1, "Description is required"),
119+
price: z.number().min(0, "Price must be positive"),
120+
duration: z.string().min(1, "Duration is required"),
121+
features: z.array(z.string().min(1)).min(1, "At least one feature is required"),
122+
category: z.string().min(1, "Category is required"),
123+
is_active: z.boolean(),
124+
});
125+
126+
type ServiceWriteInput = z.infer<typeof serviceWriteSchema>;
127+
128+
async function requireAdminUser():
129+
Promise<
130+
| { ok: true; supabase: Awaited<ReturnType<typeof createClientServerComponent>>; userId: string }
131+
| { ok: false; error: string }
132+
> {
133+
const supabase = await createClientServerComponent();
134+
const { data: user, error: userError } = await supabase.auth.getUser();
135+
if (userError || !user.user) {
136+
return { ok: false, error: "Authentication required" };
137+
}
138+
139+
const { data: userRole, error: roleError } = await supabase
140+
.from("codev")
141+
.select("role_id")
142+
.eq("id", user.user.id)
143+
.single();
144+
145+
if (roleError || userRole?.role_id !== 1) {
146+
return { ok: false, error: "Admin access required" };
147+
}
148+
149+
return { ok: true, supabase, userId: user.user.id };
150+
}
151+
152+
export async function createService(formData: ServiceWriteInput) {
153+
try {
154+
const validated = serviceWriteSchema.parse(formData);
155+
const auth = await requireAdminUser();
156+
if (!auth.ok) {
157+
return { error: auth.error };
158+
}
159+
160+
const { error } = await auth.supabase.from("services").insert({
161+
...validated,
162+
created_by: auth.userId,
163+
});
164+
165+
if (error) {
166+
console.error("Error creating service:", error);
167+
return { error: "Failed to create service" };
168+
}
169+
170+
return { error: null };
171+
} catch (error) {
172+
console.error("Error creating service:", error);
173+
return { error: "Failed to create service" };
174+
}
175+
}
176+
177+
export async function updateService(id: string, formData: ServiceWriteInput) {
178+
try {
179+
const validated = serviceWriteSchema.parse(formData);
180+
const auth = await requireAdminUser();
181+
if (!auth.ok) {
182+
return { error: auth.error };
183+
}
184+
185+
const { error } = await auth.supabase
186+
.from("services")
187+
.update(validated)
188+
.eq("id", id);
189+
190+
if (error) {
191+
console.error("Error updating service:", error);
192+
return { error: "Failed to update service" };
193+
}
194+
195+
return { error: null };
196+
} catch (error) {
197+
console.error("Error updating service:", error);
198+
return { error: "Failed to update service" };
199+
}
113200
}

‎apps/codebility/app/(marketing)/profiles/[id]/_services/query.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/codebility/app/(marketing)/profiles/_service/actions.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/codebility/app/(marketing)/profiles/_service/emailAction.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/codebility/app/(marketing)/profiles/_service/template/hire-codev-template.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/codebility/app/applicant/onboarding/_components/OnboardingClient.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import OnboardingStepper from "./OnboardingStepper";
88
import VideoPlayer from "./VideoPlayer";
99
import Quiz from "./Quiz";
1010
import Commitment from "./Commitment";
11-
import { getOnboardingProgress, completeOnboarding, saveQuizAndCommitment } from "@/actions/applicants/applicant";
12-
import { OnboardingProgressType } from "@/types/applicant-waiting";
11+
import { getOnboardingProgress, completeOnboarding, saveQuizAndCommitment } from "@/actions/applicant-onboarding/actions";
12+
import { OnboardingProgressType } from "@/types/applicant-onboarding";
1313

1414
interface OnboardingClientProps {
1515
user: any;

‎apps/codebility/app/applicant/onboarding/_components/OnboardingStepper.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import React from "react";
4-
import { OnboardingProgressType } from "@/types/applicant-waiting";
4+
import { OnboardingProgressType } from "@/types/applicant-onboarding";
55

66
interface OnboardingStepperProps {
77
progress: OnboardingProgressType;

‎apps/codebility/app/applicant/onboarding/_components/Quiz.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useState } from "react";
44
import { Button } from "@/components/ui/button";
55
import { quizQuestions, QuizQuestion } from "./quizData";
6-
import { saveQuizProgress } from "@/actions/applicants/applicant";
6+
import { saveQuizProgress } from "@/actions/applicant-onboarding/actions";
77

88
interface QuizProps {
99
applicantId: string;

‎apps/codebility/app/applicant/onboarding/_components/VideoPlayer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React, { useEffect, useRef, useState } from "react";
44
import { Button } from "@/components/ui/button";
5-
import { updateVideoProgress } from "@/actions/applicants/applicant";
5+
import { updateVideoProgress } from "@/actions/applicant-onboarding/actions";
66

77
interface VideoPlayerProps {
88
videoNumber: number;

‎apps/codebility/app/applicant/onboarding/_service/action.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)