Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update details #9

Merged
merged 13 commits into from
Jan 28, 2025
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"destructuredArrayIgnorePattern": "^_",
"ignoreRestSiblings": true
}
]
],
"react/no-unescaped-entities": 0
}
}
15 changes: 15 additions & 0 deletions public/icons/ic-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/ic-smile-xs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/people/lara-simonova.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/people/margo-lazarenkova-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/people/margo-lazarenkova.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 50 additions & 36 deletions src/api-client/answers.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
import axios from "axios";

import { IAnswerSubmitData, IResult, ISelectedResult } from "~/utils/types";
import { IAnswer } from "~/models/Answer";
import { IPerson } from "~/models/Person";

export interface IFormDataProps {
questionId: string;
question: string;
answer: string;
}

export interface IAnswerResult {
answers: IAnswer[];
person: IPerson;
}

// SUBMIT
export async function submitAnswers(formData: IFormDataProps[]) {
if (!formData.length) {
throw new Error("Input data length is 0.");
}

// Get
export async function getAnswers(slug: string): Promise<IResult | null> {
try {
const response = await axios.get<IResult>(`/api/answers/${slug}`);
const response = await axios.post<IFormDataProps[]>(
"/api/answers",
{
formData,
},
{
headers: {
"Content-Type": "application/json",
},
},
);

const data = response.data;

return data;
} catch (err) {
if (err instanceof Error) {
console.log("🔴", err.message);
console.log(err.message);
}

return null;
}
}

// Get selected answers
export async function getSelectedAnswers(
slugs: string[],
): Promise<ISelectedResult[]> {
if (!slugs.length) {
return [];
}

// GET BY SLUG
export async function getAnswersBySlug(
slug: string,
): Promise<IAnswerResult | null> {
try {
const response = await axios.get<ISelectedResult[]>(`/api/answers`, {
params: {
slugs: slugs.toString(),
},
});
const response = await axios.get<IAnswerResult>(`/api/answers/${slug}`);

const data = response.data;

Expand All @@ -42,35 +58,33 @@ export async function getSelectedAnswers(
console.log("🔴", err.message);
}

return [];
return null;
}
}

// Submit answers
export async function submitAnswers(inputData: IAnswerSubmitData[]) {
if (!inputData.length) {
throw new Error("Some params are missing: inputData.");
// GET BY SLUG ARRAY
export async function getAnswersBySlugArray(
slugs: string[],
): Promise<IAnswerResult[]> {
if (!slugs.length) {
return [];
}

try {
const response = await axios.post<IAnswerSubmitData[] | undefined>(
"/api/answers",
{
inputData,
},
{
headers: {
"Content-Type": "application/json",
},
const response = await axios.get<IAnswerResult[]>(`/api/answers`, {
params: {
slugs: slugs.toString(),
},
);
});

const data = response.data;

return data;
} catch (err) {
if (err instanceof Error) {
console.log(err.message);
console.log("🔴", err.message);
}

return [];
}
}
8 changes: 4 additions & 4 deletions src/api-client/names.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import axios from "axios";

import { IName } from "~/models";
import { IName } from "~/models/Name";

interface CreateUserProps {
interface INameProps {
name: string;
link: string;
}

// Create
export async function createName({ name, link }: CreateUserProps) {
// CREATE NAME
export async function createName({ name, link }: INameProps) {
if (!name || !link) {
throw new Error("Name and link are required.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/api-client/people.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios, { AxiosResponse } from "axios";

import { IPerson } from "~/utils/types";
import { IPerson } from "~/models/Person";

// Get Person by slug
// GET BY SLUG
export async function getPerson(slug: string): Promise<IPerson | null> {
try {
const response: AxiosResponse<IPerson> = await axios.get(
Expand All @@ -21,7 +21,7 @@ export async function getPerson(slug: string): Promise<IPerson | null> {
}
}

// Get ALL people
// GET ALL
export async function getPeople() {
try {
const response: AxiosResponse<IPerson[]> = await axios.get(`/api/people`);
Expand Down
3 changes: 2 additions & 1 deletion src/api-client/questions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios, { AxiosResponse } from "axios";

import { IQuestion } from "~/utils/types";
import { IQuestion } from "~/models/Question";

// GET ALL
export async function getQuestions() {
try {
const response: AxiosResponse<IQuestion[] | undefined> =
Expand Down
34 changes: 34 additions & 0 deletions src/api-client/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from "axios";

import { ISubscription } from "~/models/Subscription";

export type SubscriptionProps = Pick<ISubscription, "email">;

// CREATE SUBSCRIPTION
export async function createSubscription({ email }: SubscriptionProps) {
if (!email) {
throw new Error("Email is required.");
}

try {
const response = await axios.post<ISubscription>(
"api/subscriptions",
{
email,
},
{
headers: {
"Content-Type": "application/json",
},
},
);

const data = response.data;

return data;
} catch (err) {
if (err instanceof Error) {
console.log(err);
}
}
}
38 changes: 0 additions & 38 deletions src/api-client/users.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/app/api/answers/[slug]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { NextResponse } from "next/server";

import { connectDB } from "~/app/lib/connectDB";
import { IAnswer, IPerson, IQuestion } from "~/utils/types";
import { Answer, Person } from "~/models";
import { Answer, IAnswer } from "~/models/Answer";
import { IPerson, Person } from "~/models/Person";
import { IQuestion } from "~/models/Question";

interface ReqParams {
params: { slug: string };
Expand Down
Loading