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: baan select component and BaanContext #50

Merged
merged 34 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
563fbc5
chore: add structure
punchanabu Jul 12, 2024
4d7e2ae
Merge branch 'main' into punpun-fe/fdr-71-baanselect-component
punchanabu Jul 12, 2024
c4a6001
feat: getCountByBaan function
punchanabu Jul 13, 2024
54c13a4
chore: add structure
punchanabu Jul 12, 2024
f306c74
Merge branch 'main' into punpun-fe/fdr-71-baanselect-component
punchanabu Jul 13, 2024
0c45a44
feat: BaanContext
punchanabu Jul 13, 2024
d5b2c0f
feat: Display Baan
punchanabu Jul 13, 2024
2aa9f4e
feat: add check if leader
punchanabu Jul 14, 2024
0e04a0e
feat: edit Baan mode and refactor
punchanabu Jul 14, 2024
1532f46
chore: clean test folder
punchanabu Jul 14, 2024
4518796
feat: delete baan selection
punchanabu Jul 14, 2024
f08a96c
Merge branch 'dev' into punpun-fe/fdr-71-baanselect-component
punchanabu Jul 14, 2024
d99ea27
feat: add confirm baan selection
punchanabu Jul 14, 2024
75aa599
chore: uncomment necessary code
punchanabu Jul 14, 2024
1fff5f7
chore: remove test folder
punchanabu Jul 14, 2024
1e5cf12
refactor: baan component
punchanabu Jul 14, 2024
2cf4a24
feat: add default placeholder
punchanabu Jul 14, 2024
531afb7
fix: typo
punchanabu Jul 14, 2024
4d8249b
fix: typo again
punchanabu Jul 14, 2024
67542e3
chore: uncomment
punchanabu Jul 14, 2024
9811c07
build ci
bookpanda Jul 14, 2024
3d01778
remove
bookpanda Jul 14, 2024
4cc0494
dev prod pl
bookpanda Jul 14, 2024
7666651
dev prod tags
bookpanda Jul 14, 2024
01c7ccf
|
bookpanda Jul 14, 2024
e6ca975
fix
TeeGoood Jul 14, 2024
ed0926e
delete console.log
TeeGoood Jul 14, 2024
38e5a52
Merge branch 'dev' into punpun-fe/fdr-71-baanselect-component
punchanabu Jul 14, 2024
8b10080
Merge branch 'dev' into punpun-fe/fdr-71-baanselect-component
TeeGoood Jul 16, 2024
7fcf3eb
fix: minor details
punchanabu Jul 17, 2024
da12239
fix: mode condition
punchanabu Jul 17, 2024
e7004c1
Merge branch 'dev' into punpun-fe/fdr-71-baanselect-component
punchanabu Jul 17, 2024
6152207
fix: layout
punchanabu Jul 17, 2024
561ee51
fix: merge conflict
punchanabu Jul 17, 2024
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
10 changes: 10 additions & 0 deletions public/select/icon/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/select/icon/trash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/select/star/1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/select/star/2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/select/star/3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/select/star/4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/select/star/5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import localFont from 'next/font/local';
import './globals.css';
import Footer from '@/components/(main)/Footer';
import AuthProvider from '@/context/AuthContext';
import BaanProvider from '@/context/BaanContext';
import { Toaster } from 'react-hot-toast';

export const metadata: Metadata = {
Expand All @@ -21,7 +22,9 @@ export default function RootLayout({
className={`${athiti.variable} ${season.variable} ${sarun.variable} bg-1 font-athiti`}
>
<Toaster />
<AuthProvider>{children}</AuthProvider>
<AuthProvider>
<BaanProvider>{children}</BaanProvider>
</AuthProvider>
<Footer />
</body>
</html>
Expand Down
11 changes: 11 additions & 0 deletions src/components/rpkm/Baan/BaanEmpty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const BaanEmpty = () => {
return (
<div className="text-white text-3xl font-semibold">
คุณยังไม่ได้เลือกบ้าน
</div>
);
};

export default BaanEmpty;
81 changes: 81 additions & 0 deletions src/components/rpkm/Baan/BaanSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use client';
import React, { useEffect, useState } from 'react';
import BaanEmpty from '@/components/rpkm/Baan/BaanEmpty';
import Spinner from '@/components/firstdate/Spinner';
import { useBaan } from '@/context/BaanContext';
import { useAuth } from '@/context/AuthContext';
import { getGroupByUserId } from '@/utils/group';
import BaanCardsSection from './Section/BaanCardsSection';
import BaanButtonsSection from './Section/BaanButtonsSection';
import { ConfirmGroupSelection } from '@/utils/group';

interface BaanSelectProps {
mode: 'select' | 'edit';
}

const BaanSelect: React.FC<BaanSelectProps> = ({ mode }) => {
const { selectedBaan, isLoading } = useBaan();
const { user, resetContext } = useAuth();
const [isLeader, setIsLeader] = useState<boolean>(false);
const [isConfirmed, setIsConfirmed] = useState<boolean>(false);

useEffect(() => {
const checkGroupStatus = async () => {
if (user) {
const myGroup = await getGroupByUserId(user.id);
if (myGroup instanceof Error) {
resetContext();
punchanabu marked this conversation as resolved.
Show resolved Hide resolved
} else if (myGroup) {
setIsLeader(myGroup.leaderId === user.id);
setIsConfirmed(myGroup.isConfirmed);
}
}
};

checkGroupStatus();
}, [user, resetContext]);

const onConfirm = async () => {
if (user) {
const confirmedGroup = await ConfirmGroupSelection(user.id);
if (confirmedGroup instanceof Error) {
resetContext();
} else {
setIsConfirmed(true);
}
}
};
punchanabu marked this conversation as resolved.
Show resolved Hide resolved

if (isLoading) {
return <Spinner />;
}

const allSelections = Array.from({ length: 5 }, (_, i) => i + 1);

return (
<div className="flex flex-col items-center bg-zinc-800 w-80 h-auto p-5 space-y-10">
<h1 className="text-xl text-amber-100 font-bold">บ้านที่เลือกไว้</h1>
<div className="flex items-center justify-center flex-col space-y-8">
{!selectedBaan || selectedBaan.length === 0 ? (
punchanabu marked this conversation as resolved.
Show resolved Hide resolved
<BaanEmpty />
) : (
<BaanCardsSection
allSelections={allSelections}
selectedBaan={selectedBaan}
isConfirmed={isConfirmed}
mode={mode}
/>
)}
<BaanButtonsSection
mode={mode}
isLeader={isLeader}
isConfirmed={isConfirmed}
selectedBaan={selectedBaan}
onConfirm={onConfirm}
/>
</div>
</div>
);
};

export default BaanSelect;
27 changes: 27 additions & 0 deletions src/components/rpkm/Baan/Button/BaanButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

interface ButtonProps {
content: string;
onClick: () => void;
}

const Button: React.FC<ButtonProps> = ({ content, onClick }) => {
return (
<button
onClick={onClick}
className={
'flex items-center justify-center w-48 h-10 inv-rad inv-rad-2 border-8 border-rpkm-cream'
}
>
<div
className={
'flex items-center justify-center bg-rpkm-red text-rpkm-cream text-lg w-44 h-8 inv-rad inv-rad-1'
}
>
{content}
</div>
</button>
);
};

export default Button;
33 changes: 33 additions & 0 deletions src/components/rpkm/Baan/Button/BaanEditButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import Image from 'next/image';

interface BaanEditButtonProps {
onClick: () => void;
}

const BaanEditButton: React.FC<BaanEditButtonProps> = ({ onClick }) => {
return (
<button
onClick={onClick}
className={
'flex items-center justify-center w-28 h-10 inv-rad inv-rad-2 border-8 border-rpkm-cream'
}
>
<div
className={
'flex items-center justify-center space-x-1 bg-rpkm-red text-rpkm-cream text-lg w-44 h-8 inv-rad inv-rad-1'
}
>
<Image
src="/select/icon/edit.svg"
alt="แก้ไข"
width={20}
height={20}
/>
<span>แก้ไข</span>
</div>
</button>
);
};

export default BaanEditButton;
73 changes: 73 additions & 0 deletions src/components/rpkm/Baan/Card/BaanCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';
import Image from 'next/image';
import { cn } from '@/lib/utils';
import trashIcon from '@public/select/icon/trash.svg';

interface BaanCardProps {
number: number;
imageSrc?: string;
title?: string;
isEmpty?: boolean;
mode: 'select' | 'edit';
onDelete?: () => void;
isConfirmed?: boolean;
}

const BaanCard: React.FC<BaanCardProps> = ({
number,
imageSrc,
title,
isEmpty = false,
mode,
onDelete,
isConfirmed = false,
}) => {
return (
<div className="flex items-center justify-center flex-col space-y-2">
<div
className={cn(
'relative flex flex-col justify-center items-center px-1 bg-white w-20 h-28',
isEmpty && 'border-2 border-dashed border-rpkm-green bg-opacity-0'
)}
>
<div className="absolute -top-3 flex items-center justify-center w-8 h-8">
<Image
src={`/select/star/${number}.svg`}
alt={'Empty Baan'}
width={32}
height={32}
/>
</div>
{!isEmpty && imageSrc && title && (
<div className="w-full h-full flex flex-col items-center justify-center space-y-1">
<Image
src={imageSrc}
alt={title}
width={80}
height={80}
className="max-h-20"
/>
<span className="text-sm font-normal">{title}</span>
</div>
)}
{isEmpty && mode === 'edit' && (
<div className="w-5 h-5 rounded-full flex items-center justify-center bg-rpkm-green text-white">
+
</div>
)}
</div>
{mode === 'edit' && !isConfirmed && onDelete && (
<Image
src={trashIcon}
alt="ลบ"
width={15}
height={15}
onClick={onDelete}
className="cursor-pointer"
/>
)}
</div>
);
};

export default BaanCard;
Loading
Loading