-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from AloyBranCheung/dev
Dev
- Loading branch information
Showing
62 changed files
with
1,558 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,6 @@ yarn-error.log* | |
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
.env | ||
.env | ||
|
||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20231104164111_add_gym_location_to_workout_plan_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[gymLocation]` on the table `WorkoutPlan` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `gymLocation` to the `WorkoutPlan` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "WorkoutPlan" ADD COLUMN "gymLocation" TEXT NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "WorkoutPlan_gymLocation_key" ON "WorkoutPlan"("gymLocation"); |
27 changes: 27 additions & 0 deletions
27
prisma/migrations/20231104232149_update_gym_location_relations/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `gymLocation` on the `WorkoutPlan` table. All the data in the column will be lost. | ||
*/ | ||
-- DropIndex | ||
DROP INDEX "WorkoutPlan_gymLocation_key"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "WorkoutPlan" DROP COLUMN "gymLocation"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "GymLocation" ( | ||
"gymId" UUID NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "GymLocation_pkey" PRIMARY KEY ("gymId") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "GymLocation_gymId_key" ON "GymLocation"("gymId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "GymLocation" ADD CONSTRAINT "GymLocation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("userId") ON DELETE RESTRICT ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20231105001258_add_optional_field_for_gym_location/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "GymLocation" ALTER COLUMN "description" DROP NOT NULL; |
11 changes: 11 additions & 0 deletions
11
prisma/migrations/20231105005838_add_gym_location_column_to_workout_plan_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `gymId` to the `WorkoutPlan` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "WorkoutPlan" ADD COLUMN "gymId" UUID NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "WorkoutPlan" ADD CONSTRAINT "WorkoutPlan_gymId_fkey" FOREIGN KEY ("gymId") REFERENCES "GymLocation"("gymId") ON DELETE RESTRICT ON UPDATE CASCADE; |
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20231105020921_add_cascade_for_delete/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "WorkoutPlan" DROP CONSTRAINT "WorkoutPlan_gymId_fkey"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "WorkoutPlan" ADD CONSTRAINT "WorkoutPlan_gymId_fkey" FOREIGN KEY ("gymId") REFERENCES "GymLocation"("gymId") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
# dev docker compose setup | ||
docker compose -f ../docker-compose.dev.yml up --build --detach | ||
./logs.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# dev logs | ||
docker compose -f ../docker-compose.dev.yml logs --timestamps --follow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
# if i feel like it | ||
yarn lint | ||
yarn jest-ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# wipe db | ||
yarn prisma migrate reset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# restart docker compose setup | ||
./stop.sh | ||
./dev.sh | ||
./logs.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# stop all containers and remove all containers | ||
docker stop $(docker ps -aq) && docker rm $(docker ps -aq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
# development only migrate db | ||
yarn prisma migrate dev | ||
yarn prisma generate |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from "react" | ||
// react-hook-forms | ||
import { useForm, FieldValues } from "react-hook-form" | ||
import { zodResolver } from "@hookform/resolvers/zod" | ||
// z | ||
import { z } from "zod" | ||
// types/validators | ||
import { AddGymLocationSchema } from "src/validators/workout-schema" | ||
import FormInput from "../UI/FormInput" | ||
import PrimaryButton from "../UI/PrimaryButton" | ||
// hooks | ||
import useMutationAddGymLocation from "src/hooks/useMutationAddGymLocation" | ||
import useToastMessage, { ToastMessage } from "src/hooks/useToastMessage" | ||
|
||
interface AddGymLocationModalProps { | ||
// trigger setValues in the parent form for the new location from getValues().name in this form | ||
onSuccessAdd: (gymName: string) => void | ||
} | ||
|
||
export default function AddGymLocationModal({ | ||
onSuccessAdd, | ||
}: AddGymLocationModalProps) { | ||
const toastMessage = useToastMessage() | ||
|
||
const { handleSubmit, reset, control } = useForm< | ||
z.infer<typeof AddGymLocationSchema> & FieldValues | ||
>({ | ||
defaultValues: { | ||
description: "", | ||
name: "", | ||
}, | ||
resolver: zodResolver(AddGymLocationSchema), | ||
}) | ||
|
||
const { mutate, isLoading } = useMutationAddGymLocation( | ||
(data) => { | ||
toastMessage("Successfully added gym location.", ToastMessage.Success) | ||
onSuccessAdd(data.gymId) | ||
reset() | ||
}, | ||
() => toastMessage("Error adding gym location.", ToastMessage.Error) | ||
) | ||
|
||
const handleSubmitForm = (data: z.infer<typeof AddGymLocationSchema>) => { | ||
mutate(data) | ||
} | ||
|
||
return ( | ||
<form | ||
className="flex flex-col gap-2" | ||
onSubmit={handleSubmit(handleSubmitForm)} | ||
> | ||
<FormInput control={control} name="name" /> | ||
<FormInput control={control} name="description" required={false} /> | ||
<PrimaryButton | ||
label="Submit" | ||
type="submit" | ||
className="py-2 px-3 mt-5" | ||
isLoading={isLoading} | ||
/> | ||
</form> | ||
) | ||
} |
Oops, something went wrong.