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

Feature/fix chakra progress theme error #115

Merged
merged 5 commits into from
May 19, 2024
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
15 changes: 15 additions & 0 deletions components/atoms/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Progress } from "@chakra-ui/react";

interface IProgressBar {
value: number;
colorScheme?: "mintTheme";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 prop은 당장은 상수여서 엄청 필요한 prop은 아닌 것 같습니다 :)

혹시 어떤 의도로 prop을 만드셨는지 궁금합니다 :)

hasStripe?: boolean;
}

export default function ProgressBar({
value,
colorScheme = "mintTheme",
hasStripe = false,
}: IProgressBar) {
return <Progress value={value} colorScheme={colorScheme} hasStripe={hasStripe} />;
}
4 changes: 2 additions & 2 deletions components/molecules/ProgressStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Progress } from "@chakra-ui/react";
import styled from "styled-components";
import ProgressBar from "../atoms/ProgressBar";

interface IProgressStatus {
value: number;
Expand All @@ -8,7 +8,7 @@ interface IProgressStatus {
function ProgressStatus({ value }: IProgressStatus) {
return (
<Layout>
<Progress value={value} size="sm" />
<ProgressBar value={value} />
</Layout>
);
}
Expand Down
26 changes: 26 additions & 0 deletions models/gift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mongoose, { Model, Schema } from "mongoose";

import { IStoreApplicant } from "../types/models/store";

const giftSchema: Schema = new Schema(
{
uid: { type: String, ref: "User" },
name: { type: String, ref: "User" },
cnt: { type: Number, default: 0 },
giftId: { type: Number },
},
{
toJSON: {
transform(_doc, ret) {
delete ret.createdAt;
delete ret.upadtedAt;
delete ret.__v;
return ret;
},
},
},
);

export const GiftModel =
(mongoose.models.GiftModel as Model<IStoreApplicant, {}, {}, {}>) ||
mongoose.model<IStoreApplicant>("GiftModel", giftSchema);
8 changes: 4 additions & 4 deletions pageTemplates/point/pointScore/PointScoreBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Badge, Progress } from "@chakra-ui/react";
import { Badge } from "@chakra-ui/react";
import { faQuestionCircle } from "@fortawesome/pro-light-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useSession } from "next-auth/react";
import { useEffect, useState } from "react";
import styled from "styled-components";
import ProgressBar from "../../../components/atoms/ProgressBar";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 당장 적용할 수는 없겠지만 tsconfig에 절대 경로 설정을 하게 되면 import 경로가 조금 더 간결해질 수도 있을 것 같습니다 :)

import {
BADGE_COLOR_MAPPINGS,
Expand Down Expand Up @@ -80,11 +81,10 @@ function PointScoreBar({ myScore, hasQuestion = true }: IPointScoreBar) {
</div>
)}
</Grade>
<Progress
<ProgressBar
value={(1 - (nextBadgePoint - myScore) / badgeGap) * 100}
height="12px"
colorScheme="mintTheme"
hasStripe
hasStripe={true}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 convention으로 정할 수도 있을 것 같은 부분인 것 같습니다 :)

혹시 변수로 정해지는 boolean prop이 아닐 때도 true/false를 명시하는 걸 선호하실까요? :)

</Layout>

Expand Down
22 changes: 22 additions & 0 deletions pages/api/store/[id].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextApiRequest, NextApiResponse } from "next";

import { BadRequestError } from "../../../libs/backend/custom-error";
import dbConnect from "../../../libs/backend/dbConnect";
import { GiftModel } from "../../../models/gift";

export default async function getGift(req: NextApiRequest, res: NextApiResponse) {
await dbConnect();

if (req.method === "GET") {
const { id } = req.query;

const giftUsers = await GiftModel.find({ giftId: id }).select(
"-_id -createdAt -updatedAt -__v",
);
if (!giftUsers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별 건 아니지만 여기 if 문 위에 개행이 들어가면 조금 더 깔끔할 수도 있을 것 같습니다 :)

  • 아래 소스 파일을 봤을 땐 if 문 개행에 대한 컨벤션이 따로 없는 것 같습니다 :)
  • 어떤 컨벤션을 정하거나 지금처럼 질서 부여하지 않고 갈 수도 있을 것 같습니다 :)

throw new BadRequestError("정보에 해당하는 유저가 존재하지 않습니다.");
}

res.status(200).json({ users: giftUsers });
}
}
52 changes: 52 additions & 0 deletions pages/api/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { NextApiRequest, NextApiResponse } from "next";

import { BadRequestError } from "../../../libs/backend/custom-error";
import dbConnect from "../../../libs/backend/dbConnect";
import { GiftModel } from "../../../models/gift";

export default async function giftController(req: NextApiRequest, res: NextApiResponse) {
await dbConnect();

if (req.method === "POST") {
const { name, uid, cnt, giftId } = req.body;

const existingUser = await GiftModel.findOne({ uid, giftId });

if (existingUser) {
const user = await GiftModel.findOneAndUpdate(
{ uid },
{ name, uid, cnt: existingUser.cnt + cnt, giftId },
{ new: true, runValidators: true },
);
if (!user) {
throw new BadRequestError("정보에 해당하는 유저가 존재하지 않습니다.");
}

const resUser = {
name: user.name,
uid: user.uid,
cnt: user.cnt,
giftId: user.giftId,
};

return res.status(200).json({ user: resUser });
}
const newUser = await GiftModel.create({ name, uid, cnt, giftId });
const user = {
name: newUser.name,
uid: newUser.uid,
cnt: newUser.cnt,
giftId: newUser.giftId,
};
res.status(200).json({ user });
}
if (req.method === "GET") {
const giftUsers = await GiftModel.find({})
.sort("createdAt")
.select("-_id -createdAt -updatedAt -__v");

res.status(200).json({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 부분입니다 :)

  • 200 등의 HttpStatusCode를 enum이나 리터럴 선언을 해서 가져다 쓰면 의도가 조금 더 명확하게 표현될 수도 있을 것 같습니다.
  • 다만 http status는 너무 익숙해서 숫자가 더 간결할 수도 있을 것 같습니다 :)
  • 만약 200이 아니라 201, 204, 301, 302, 304, 400, 401, 403, 404, 500, 502, 503 이렇게 섞어쓰게 된다면 상수화를 하면 위의 이유 때문에 조금 더 좋을 것 같습니다 :)

users: giftUsers,
});
}
}
2 changes: 1 addition & 1 deletion pages/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useAdminStudyRecordQuery } from "../hooks/admin/quries";
import { useImageUploadMutation } from "../hooks/image/mutations";
import { studyDateStatusState } from "../recoils/studyRecoils";
function Test() {
const { data } = useAdminStudyRecordQuery(dayjs("2024-04-01"), dayjs("2024-04-07"), null, "인천");
const { data } = useAdminStudyRecordQuery(dayjs("2024-04-16"), dayjs("2024-04-30"), null, "인천");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단순 궁금증입니다 :)

  • 혹시 이 test 페이지의 의도가 테스트 용도라면 이 소스 파일도 버전 관리가 되어야 하는 것인지 궁금합니다 :)

console.log(data);

const a = useRecoilValue(studyDateStatusState);
Expand Down
24 changes: 24 additions & 0 deletions storage/winRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,30 @@ export const WIN_RECORD: {
detail: "알파벳 수집 보상",
present: "스타벅스 기프티콘",
},
{
name: "이아",
date: "4/29",
detail: "스토어 당첨 보상",
present: "불닭 + 바나나 우유",
},
{
name: "이아",
date: "4/29",
detail: "스토어 당첨 보상",
present: "불닭 + 바나나 우유",
},
{
name: "김석",
date: "4/29",
detail: "스토어 당첨 보상",
present: "롯데시네마 영화관람권",
},
{
name: "김사",
date: "4/29",
detail: "스토어 당첨 보상",
present: "롯데시네마 영화관람권",
},
];

export const PROMOTION_WIN = [
Expand Down
10 changes: 0 additions & 10 deletions theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ const theme = extendTheme({
},
},
},
Progress: {
baseStyle: {
track: {
bg: "var(--font-h7)",
},
filledTrack: {
bg: "var(--color-mint)",
},
},
},
},
});

Expand Down
Loading