-
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.
- Loading branch information
Showing
11 changed files
with
179 additions
and
56 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
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,82 @@ | ||
import { InterestedSteps, InterestedUser } from 'interfaces/interested' | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
ModalCloseButton, | ||
UseDisclosureProps, | ||
} from '@chakra-ui/react' | ||
import Table from 'components/global/Table' | ||
import { CellProps, Column } from 'react-table' | ||
import { Select } from 'chakra-react-select' | ||
import { useState } from 'react' | ||
import axios from 'libs/axios' | ||
import { config } from 'config' | ||
|
||
interface Props extends UseDisclosureProps { | ||
interestedUsers: InterestedUser[] | ||
} | ||
|
||
const InterestedModal: React.FC<Props> = ({ interestedUsers: originalInterestedUser, isOpen, onClose }) => { | ||
const [interestedUsers, setInterestedUsers] = useState<InterestedUser[]>(originalInterestedUser) | ||
return ( | ||
<Modal isOpen={isOpen || false} onClose={onClose as () => void} size="full"> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>ผู้ที่สนใจสัตว์</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<Table | ||
columns={ | ||
[ | ||
{ accessor: 'name', Header: 'ชื่อ' }, | ||
{ accessor: 'phone', Header: 'โทรศัพท์' }, | ||
{ | ||
accessor: 'step', | ||
Header: 'สถานะ', | ||
Cell: ({ row }: CellProps<InterestedUser>) => ( | ||
<Select | ||
focusBorderColor="green.500" | ||
defaultValue={{ label: row.original.step, value: row.original.step }} | ||
options={InterestedSteps.map(step => ({ label: step, value: step }))} | ||
onChange={newVal => { | ||
const find = interestedUsers.find( | ||
u => u.user_id === row.original.user_id && u.pet_id === row.original.pet_id, | ||
) | ||
const newArr: InterestedUser[] = [ | ||
...interestedUsers.filter( | ||
u => !(u.user_id === row.original.user_id && u.pet_id === row.original.pet_id), | ||
), | ||
{ ...find, step: newVal?.value } as InterestedUser, | ||
] | ||
// Update API | ||
axios.put( | ||
config.interest.PUT_update.replace(':pet_id', String(row.original.pet_id)), | ||
{}, | ||
{ | ||
params: { | ||
step: newVal?.value, | ||
user_id: row.original.user_id, | ||
}, | ||
}, | ||
) | ||
|
||
setInterestedUsers(newArr) | ||
}} | ||
menuPosition="fixed" | ||
/> | ||
), | ||
}, | ||
] as Column<InterestedUser>[] | ||
} | ||
data={interestedUsers} | ||
/> | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default InterestedModal |
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
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 |
---|---|---|
@@ -1,12 +1,26 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import { Pet } from './Pet' | ||
import { User } from './User' | ||
|
||
// eslint-disable-next-line no-shadow | ||
export enum InterestedStep { | ||
PENDING = 'ได้รับข้อมูลแล้ว', | ||
REVIEWING = 'กำลังตรวจสอบข้อมูล และติดต่อกลับ', | ||
ADOPED = 'เสร็จสิ้น', | ||
} | ||
|
||
export interface Interested { | ||
user_id: string | ||
pet_id: number | ||
step: 'PENDING' | 'REVIEWING' | 'ADOPED' | ||
step: InterestedStep | ||
} | ||
|
||
export const InterestedSteps: InterestedStep[] = [ | ||
InterestedStep.PENDING, | ||
InterestedStep.REVIEWING, | ||
InterestedStep.ADOPED, | ||
] | ||
|
||
export interface InterestedPet extends Interested, Pet {} | ||
|
||
export interface InterestedUser extends Interested, User {} |
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
Oops, something went wrong.