diff --git a/Modules/Client/Transformers/EmployeeData/UserProfile/DataMemberResource.php b/Modules/Client/Transformers/EmployeeData/UserProfile/DataMemberResource.php new file mode 100644 index 00000000..40ac6fba --- /dev/null +++ b/Modules/Client/Transformers/EmployeeData/UserProfile/DataMemberResource.php @@ -0,0 +1,46 @@ + [ + 'name' => $this->full_name ?? null, + 'weight' => $this->person->last_weight_kg ?? null, + 'height' => $this->person->last_height_kg ?? null, + 'placeOfBirth' => ucwords($this->person->birth_place) ?? null, + 'dateOfBirth' => $this->birth_date ?? $this->person->birth_date, + 'gender' => ucwords(strtolower($this->gender ?? $this->person->gender)), + 'phoneNumber' => $this->person->phone ?? null, + 'email' => $this->email ?? ($this->person->email ?? null), + 'address' => $this->person->last_height_kg ?? null, + 'idNumber' => $this->person->nik ?? null, + 'religion' => ucwords(strtolower($this->person->religion)) ?? null, + 'maritalStatus' => $this->marital_status, + 'education' => ucwords(strtolower($this->person->last_education)) ?? null, + 'occupation' => null, + ], + 'families' => collect($this->families)->map(function ($family) { + return [ + 'name' => $family->full_name ?? null, + 'relationship' => $family->relationship ?? null, + 'dateOfBirth' => $family->birth_date ?? $family->person->birth_date, + 'email' => $this->email ?? ($this->person->email ?? null), + 'phoneNumber' => $this->person->phone ?? null, + 'status' => $this->status ?? null + ]; + })->all() + ]; + } +} diff --git a/app/Models/Person.php b/app/Models/Person.php index 81ac542d..4c61f862 100644 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -40,7 +40,7 @@ class Person extends Model 'updated_by', 'deleted_by' ]; - + protected $hidden = [ 'created_at', 'updated_at', @@ -126,6 +126,11 @@ class Person extends Model return $this->morphMany(AppointmentParticipant::class, 'participantable'); } + public function member() + { + return $this->hasOne(Member::class); + } + public function setGenderAttribute($value) { if ($value == "M" || $value == "L") { @@ -139,7 +144,6 @@ class Person extends Model public function getGenderAttribute() { - if ($this->attributes['gender'] == "male" || $this->attributes['gender'] == "L") { return "male"; } else if ($this->attributes['gender'] == "female" || $this->attributes['gender'] == "P") { @@ -148,9 +152,4 @@ class Person extends Model return "other"; } } - - public function updatePerson() - { - $this-> update ( $data ); - } } diff --git a/frontend/client-portal/src/@types/member.ts b/frontend/client-portal/src/@types/member.ts index c38b0640..348b2f5b 100644 --- a/frontend/client-portal/src/@types/member.ts +++ b/frontend/client-portal/src/@types/member.ts @@ -1,21 +1,45 @@ -// ---------------------------------------------------------------------- - export type Member = { - id: string, - member_id: string, - record_type: string, - payor_id: string, - user_id: string, - name_prefix: string, - name: string, - name_suffix: string, - birth_date: string, - gender: string, - language: string, - race: string, - marital_status: string, - principal_id: string, - relation_with_principal: string, - bpjs_class: string, - active: string, + id: string; + member_id: string; + record_type: string; + payor_id: string; + user_id: string; + name_prefix: string; + name: string; + name_suffix: string; + birth_date: string; + gender: string; + language: string; + race: string; + marital_status: string; + principal_id: string; + relation_with_principal: string; + bpjs_class: string; + active: string; +}; + +export type PersonalInformationType = { + name: string; + weight: number; + height: number; + placeOfBirth: string; + dateOfBirth: string; + gender: string; + phoneNumber: string; + email: string; + address: string; + idNumber: string; + religion: string; + maritalStatus: string; + education: string; + occupation: string; +}; + +export type FamilyInformationtype = { + name: string; + relationship: string; + dateOfBirth: string; + email: string; + phoneNumber: string; + status: string; }; diff --git a/frontend/client-portal/src/layouts/dashboard/header/AccountPopover.tsx b/frontend/client-portal/src/layouts/dashboard/header/AccountPopover.tsx index 300cc955..d492c054 100644 --- a/frontend/client-portal/src/layouts/dashboard/header/AccountPopover.tsx +++ b/frontend/client-portal/src/layouts/dashboard/header/AccountPopover.tsx @@ -33,8 +33,6 @@ export default function AccountPopover() { const navigate = useNavigate(); const { logout, user } = useAuth(); - console.log(user); - const handleOpen = (event: React.MouseEvent) => { setOpen(event.currentTarget); }; diff --git a/frontend/client-portal/src/pages/EmployeeData/UserProfile.tsx b/frontend/client-portal/src/pages/EmployeeData/UserProfile.tsx index 1bd40e40..1741e268 100644 --- a/frontend/client-portal/src/pages/EmployeeData/UserProfile.tsx +++ b/frontend/client-portal/src/pages/EmployeeData/UserProfile.tsx @@ -1,68 +1,72 @@ // mui -import { IconButton, Container, Grid, Stack, Typography } from '@mui/material'; +import { Container, Grid, Stack, Typography } from '@mui/material'; // components import Page from '../../components/Page'; -import Iconify from '../../components/Iconify'; // utils import useSettings from '../../hooks/useSettings'; -// section -import CardPersonalInformation from '../../sections/alarm-center/user-profile/CardPersonalInformation'; -import CardFamilyInformation from '../../sections/alarm-center/user-profile/CardFamilyInformation'; -import CardPolicyNumber from '../../sections/alarm-center/user-profile/CardPolicyNumber'; -import CardBenefitSummary from '../../sections/alarm-center/user-profile/CardBenefitSummary'; -import CardClaimHistory from '../../sections/alarm-center/user-profile/CardClaimHistory'; // react import { useNavigate, useParams } from 'react-router-dom'; -import ButtonBack from '../../components/ButtonBack'; import { useEffect, useState, useContext } from 'react'; import axios from '../../utils/axios'; import { UserCurrentCorporateContext } from '../../contexts/UserCurrentCorporate'; import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos'; +import CardPersonalInformation from '../../sections/employee-data/user-profile/CardPersonalInformation'; +import CardFamilyInformation from '../../sections/employee-data/user-profile/CardFamilyInformation'; +import { FamilyInformationtype, PersonalInformationType } from '../../@types/member'; // ---------------------------------------------------------------------- +type UserProfileDataType = { + person: PersonalInformationType; + families: FamilyInformationtype[]; +}; + export default function UserProfile() { const { themeStretch } = useSettings(); const navigate = useNavigate(); - const [data, setData] = useState(); + const [data, setData] = useState(); const { corporateValue } = useContext(UserCurrentCorporateContext); const { id } = useParams(); useEffect(() => { - axios - .get(corporateValue + '/members/' + id) - .then((response) => { - setData(response.data); - }) - .catch((error) => { - console.error(error); - }); + (async () => { + await axios + .get(corporateValue + '/members/' + id) + .then((response) => { + setTimeout(() => { + console.log(response.data); + setData(response.data); + }, 1000); + }) + .catch((error) => { + if (error.response.data.statusCode === 404) { + navigate(-1); + } else { + console.error(error); + } + }); + })(); }, []); -// console.log('data', data); - return ( - {/* navigate()}> - - */} - navigate(-1)}/> - Profile + navigate(-1)} /> + + Profile + - {data ? ( {/* Row 1 */} - + - + - ) : ''} ); diff --git a/frontend/client-portal/src/sections/employee-data/user-profile/CardFamilyInformation.tsx b/frontend/client-portal/src/sections/employee-data/user-profile/CardFamilyInformation.tsx new file mode 100644 index 00000000..35902c4e --- /dev/null +++ b/frontend/client-portal/src/sections/employee-data/user-profile/CardFamilyInformation.tsx @@ -0,0 +1,165 @@ +/* ------------------------------- material ui ------------------------------ */ +import { Card, Typography, Grid, Skeleton, Stack } from '@mui/material'; +import { fDateBirth } from '../../../utils/formatTime'; + +type CardFamilyInformationProps = { + data?: { + name: string; + relationship: string; + dateOfBirth: string; + email: string; + phoneNumber: string; + status: string; + }[]; +}; + +export default function CardFamilyInformation({ data }: CardFamilyInformationProps) { + console.log(data); + + return ( + + + + + {data ? 'Beneficiary / Family' : } + + + + {data && data.length > 0 ? ( + data.map((familyMember, index) => ( + + + + + + + {familyMember.name ? familyMember.name : '-'} + + + {familyMember.relationship ? familyMember.relationship : '-'} + + + + + + + Date Of Birth + + + + + {familyMember.dateOfBirth ? fDateBirth(familyMember.dateOfBirth) : '-'} + + + + + + + Email + + + + + {familyMember.email ? familyMember.email : '-'} + + + + + + + Phone Number + + + + + {familyMember.phoneNumber ? familyMember.phoneNumber : '-'} + + + + + + + Status + + + + + {familyMember.status ? familyMember.status : '-'} + + + + + + + )) + ) : ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + )} + + + + ); +} diff --git a/frontend/client-portal/src/sections/employee-data/user-profile/CardPersonalInformation.tsx b/frontend/client-portal/src/sections/employee-data/user-profile/CardPersonalInformation.tsx new file mode 100644 index 00000000..ed0aa9ba --- /dev/null +++ b/frontend/client-portal/src/sections/employee-data/user-profile/CardPersonalInformation.tsx @@ -0,0 +1,280 @@ +/* ------------------------------- Material UI ------------------------------ */ +import { Card, Stack, Typography, Grid, Skeleton } from '@mui/material'; +import { fDateBirth } from '../../../utils/formatTime'; + +type CardPersonalInformationProps = { + data?: { + name: string; + weight: number; + height: number; + placeOfBirth: string; + dateOfBirth: string; + gender: string; + phoneNumber: string; + email: string; + address: string; + idNumber: string; + religion: string; + maritalStatus: string; + education: string; + occupation: string; + }; +}; + +export default function CardPersonalInformation({ data }: CardPersonalInformationProps) { + return ( + + + + + {data ? 'Personal Information' : } + + + + {/* First */} + + + + {data ? 'Full Name' : } + + + {data ? data.name ? data.name : '-' : } + + + + + + + {data ? 'Weight' : } + + + {data ? ( + data.weight ? ( + `${data.weight} kg` + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Height' : } + + + {data ? ( + data.height ? ( + `${data.height} cm` + ) : ( + '-' + ) + ) : ( + + )} + + + + {/* Second */} + + + + {data ? 'Place of Birth' : } + + + {data ? ( + data.placeOfBirth ? ( + data.placeOfBirth + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Date of Birth' : } + + + {data ? ( + data.dateOfBirth ? ( + fDateBirth(data.dateOfBirth) + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Gender' : } + + + {data ? ( + data.gender ? ( + data.gender + ) : ( + '-' + ) + ) : ( + + )} + + + + {/* Third */} + + + + {data ? 'Phone Number' : } + + + {data ? ( + data.phoneNumber ? ( + data.phoneNumber + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Email' : } + + + {data ? data.email ? data.email : '-' : } + + + + {/* Four */} + + + + {data ? 'Address' : } + + + {data ? ( + data.address ? ( + data.address + ) : ( + '-' + ) + ) : ( + + )} + + + + {/* Five */} + + + + {data ? 'ID Number' : } + + + {data ? ( + data.idNumber ? ( + data.idNumber + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Religion' : } + + + {data ? ( + data.religion ? ( + data.religion + ) : ( + '-' + ) + ) : ( + + )} + + + + {/* Six */} + + + + {data ? 'Marital Status' : } + + + {data ? ( + data.maritalStatus ? ( + data.maritalStatus + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Education' : } + + + {data ? ( + data.education ? ( + data.education + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + {data ? 'Occupation' : } + + + {data ? ( + data.occupation ? ( + data.occupation + ) : ( + '-' + ) + ) : ( + + )} + + + + + + + ); +} diff --git a/frontend/client-portal/src/utils/formatTime.ts b/frontend/client-portal/src/utils/formatTime.ts index ed88dcae..65e936d4 100644 --- a/frontend/client-portal/src/utils/formatTime.ts +++ b/frontend/client-portal/src/utils/formatTime.ts @@ -7,6 +7,10 @@ export function fDate(date: Date | string | number) { return format(new Date(date), 'dd MMMM yyyy'); } +export function fDateBirth(date: Date | string | number) { + return format(new Date(date), 'dd MMM yyyy'); +} + export function fDateTime(date: Date | string | number) { return format(new Date(date), 'dd MMM yyyy hh:mm'); } @@ -19,7 +23,6 @@ export function fDateTimeSuffix(date: Date | string | number) { return format(new Date(date), 'dd/MM/yyyy hh:mm p'); } - export function fDateSuffix(date: Date | string | number) { return format(new Date(date), 'dd MMM yyyy'); }