@@ -47,10 +47,12 @@ const formSchema = z.object({
4747 . max ( 16 ) ,
4848 lineId : z . string ( ) . max ( 30 ) . optional ( ) ,
4949 facebook : z . string ( ) . max ( 60 ) . optional ( ) ,
50- currentAddressLatitude : z . number ( ) ,
51- currentAddressLongitude : z . number ( ) ,
50+ currentAddressLatitude : z . number ( ) . optional ( ) ,
51+ currentAddressLongitude : z . number ( ) . optional ( ) ,
5252 currentAddressProvinceId : z . number ( ) ,
53- currentAddressDistrictId : z . number ( ) ,
53+ currentAddressDistrictId : z
54+ . number ( )
55+ . min ( 1 , { message : "กรุณาเลือกเขต/อำเภอ" } ) ,
5456 currentAddressNumber : z . string ( ) . min ( 1 ) . max ( 60 ) ,
5557 currentAddressOther : z . string ( ) . min ( 1 ) . max ( 400 ) ,
5658 hometownAddressLongitude : z . number ( ) . optional ( ) ,
@@ -269,6 +271,17 @@ export default function FormComponent2({
269271 router . push ( "/register/onboarding/3" ) ;
270272 }
271273
274+ const sortedProvinces = useMemo ( ( ) => {
275+ if ( ! provinces ) return [ ] ;
276+ const bkk = provinces . find ( ( p ) => p . nameTh === "กรุงเทพมหานคร" ) ;
277+ const others = provinces
278+ . filter ( ( p ) => p . nameTh !== "กรุงเทพมหานคร" )
279+ . sort ( ( a , b ) =>
280+ ( a . nameTh ?? "" ) . localeCompare ( b . nameTh ?? "" , "th" ) ,
281+ ) ;
282+ return bkk ? [ bkk , ...others ] : others ;
283+ } , [ provinces ] ) ;
284+
272285 return (
273286 < Card className = "p-6 md:p-8" >
274287 < Form { ...form } >
@@ -518,28 +531,6 @@ export default function FormComponent2({
518531 </ section >
519532
520533 < section className = "flex flex-col gap-2" >
521- < div className = "h-60 overflow-hidden rounded-lg border-[6px] border-white" >
522- < GoogleMap
523- onLocationSelect = { handleCurrentLocationSelect }
524- selectedLocation = {
525- selectedCurrentLocationLat &&
526- selectedCurrentLocationLng
527- ? {
528- lat : parseFloat (
529- selectedCurrentLocationLat ,
530- ) ,
531- lng : parseFloat (
532- selectedCurrentLocationLng ,
533- ) ,
534- }
535- : undefined
536- }
537- width = "100%"
538- height = "100%"
539- placeholder = "ระบุตำแหน่งที่อยู่ปัจจุบัน"
540- />
541- </ div >
542-
543534 < FormField
544535 control = { form . control }
545536 name = "currentAddressLatitude"
@@ -582,22 +573,25 @@ export default function FormComponent2({
582573 }
583574 onValueChange = { ( value ) => {
584575 const selectedProvinceString =
585- provinces . find (
576+ sortedProvinces . find (
586577 ( province ) =>
587578 province . nameTh ===
588579 value ,
589580 ) ;
590-
591581 if ( ! selectedProvinceString ) {
592582 return ;
593583 }
594-
595584 field . onChange (
596585 selectedProvinceString . id ,
597586 ) ;
598587 setSelectedCurrentProvince (
599588 selectedProvinceString . id ,
600589 ) ;
590+ // Reset district when province changes
591+ form . setValue (
592+ "currentAddressDistrictId" ,
593+ 0 ,
594+ ) ; // ใช้ 0 แทน undefined
601595 } }
602596 >
603597 < FormControl >
@@ -606,7 +600,7 @@ export default function FormComponent2({
606600 </ SelectTrigger >
607601 </ FormControl >
608602 < SelectContent >
609- { provinces . map ( ( province ) => (
603+ { sortedProvinces . map ( ( province ) => (
610604 < SelectItem
611605 key = { province . provinceCode }
612606 value = {
@@ -629,7 +623,7 @@ export default function FormComponent2({
629623 render = { ( { field } ) => (
630624 < FormItem className = "!pt-0" >
631625 < FormLabel >
632- เขตที่อยู่ปัจจุบัน
626+ อำเภอ/ เขตที่อยู่ปัจจุบัน
633627 < span className = "text-red-500" > *</ span >
634628 </ FormLabel >
635629 < Select
@@ -725,7 +719,7 @@ export default function FormComponent2({
725719 </ FormLabel >
726720 < FormControl >
727721 < Input
728- placeholder = "กรอกที่อยู่ปัจจุบัน"
722+ placeholder = "กรอกที่อยู่ปัจจุบัน (หมู่บ้าน/ซอย/ถนน/ตำบล) "
729723 { ...field }
730724 />
731725 </ FormControl >
@@ -737,28 +731,6 @@ export default function FormComponent2({
737731
738732 { selectedCountry === 221 ? ( // Thailand
739733 < section className = "flex flex-col gap-2" >
740- < div className = "h-60 overflow-hidden rounded-lg border-[6px] border-white" >
741- < GoogleMap
742- onLocationSelect = { handleHomeLocationSelect }
743- selectedLocation = {
744- selectedHomeLocationLat &&
745- selectedHomeLocationLng
746- ? {
747- lat : parseFloat (
748- selectedHomeLocationLat ,
749- ) ,
750- lng : parseFloat (
751- selectedHomeLocationLng ,
752- ) ,
753- }
754- : undefined
755- }
756- width = "100%"
757- height = "100%"
758- placeholder = "ระบุตำแหน่งที่อยู่ภูมิลำเนา"
759- />
760- </ div >
761-
762734 < FormField
763735 control = { form . control }
764736 name = "hometownAddressLatitude"
@@ -786,7 +758,7 @@ export default function FormComponent2({
786758 render = { ( { field } ) => (
787759 < FormItem className = "!pt-0" >
788760 < FormLabel >
789- จังหวัดที่อยู่ภูมิลำเนา
761+ จังหวัดที่อยู่ตามบัตรประชาชน
790762 </ FormLabel >
791763 < Select
792764 value = {
@@ -820,24 +792,26 @@ export default function FormComponent2({
820792 >
821793 < FormControl >
822794 < SelectTrigger >
823- < SelectValue placeholder = "เลือกจังหวัดที่อยู่ภูมิลำเนา " />
795+ < SelectValue placeholder = "เลือกจังหวัดที่อยู่ตามบัตรประชาชน " />
824796 </ SelectTrigger >
825797 </ FormControl >
826798 < SelectContent >
827799 { /* Map through provinces data */ }
828- { provinces . map ( ( province ) => (
829- < SelectItem
830- key = {
831- province . provinceCode
832- }
833- value = {
834- province . nameTh ??
835- ""
836- }
837- >
838- { province . nameTh }
839- </ SelectItem >
840- ) ) }
800+ { sortedProvinces . map (
801+ ( province ) => (
802+ < SelectItem
803+ key = {
804+ province . provinceCode
805+ }
806+ value = {
807+ province . nameTh ??
808+ ""
809+ }
810+ >
811+ { province . nameTh }
812+ </ SelectItem >
813+ ) ,
814+ ) }
841815 </ SelectContent >
842816 </ Select >
843817 < FormMessage />
@@ -851,7 +825,7 @@ export default function FormComponent2({
851825 render = { ( { field } ) => (
852826 < FormItem className = "!pt-0" >
853827 < FormLabel >
854- เขตที่อยู่ภูมิลำเนา
828+ เขตที่อยู่ตามบัตรประชาชน
855829 </ FormLabel >
856830 < Select
857831 value = {
@@ -877,7 +851,7 @@ export default function FormComponent2({
877851 >
878852 < FormControl >
879853 < SelectTrigger >
880- < SelectValue placeholder = "เลือกเขตที่อยู่ภูมิลำเนา " />
854+ < SelectValue placeholder = "เลือกเขตที่อยู่ตามบัตรประชาชน " />
881855 </ SelectTrigger >
882856 </ FormControl >
883857 < SelectContent >
@@ -936,10 +910,12 @@ export default function FormComponent2({
936910 name = "hometownAddressOther"
937911 render = { ( { field } ) => (
938912 < FormItem >
939- < FormLabel > ที่อยู่ภูมิลำเนา</ FormLabel >
913+ < FormLabel >
914+ ที่อยู่ตามบัตรประชาชน
915+ </ FormLabel >
940916 < FormControl >
941917 < Input
942- placeholder = "กรอกที่อยู่ภูมิลำเนา "
918+ placeholder = "กรอกที่อยู่ตามบัตรประชาชน (หมู่บ้าน/ซอย/ถนน/ตำบล) "
943919 { ...field }
944920 />
945921 </ FormControl >
@@ -954,10 +930,10 @@ export default function FormComponent2({
954930 name = "hometownAddressOther"
955931 render = { ( { field } ) => (
956932 < FormItem >
957- < FormLabel > ที่อยู่ภูมิลำเนา </ FormLabel >
933+ < FormLabel > ที่อยู่ตามบัตรประชาชน </ FormLabel >
958934 < FormControl >
959935 < Input
960- placeholder = "กรอกที่อยู่ภูมิลำเนา "
936+ placeholder = "กรอกที่อยู่ตามบัตรประชาชน "
961937 { ...field }
962938 />
963939 </ FormControl >
0 commit comments