"use client" import { useEffect, useState } from 'react'; import upload from '@/app/library/upload'; import "@fortawesome/fontawesome-svg-core/styles.css"; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faTimes, faChevronLeft, faBuilding} from '@fortawesome/free-solid-svg-icons'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { FormPost, dataStatus } from './form'; import { ImageUpload } from "@/app/component/ImageUploadMass"; import { dataWilayah } from "@/app/library/loadJson"; import { Helper } from '@/app/library/prototype'; import ValidasiLogin from '@/app/component/loginvalidasi'; import useSWR, { SWRConfig } from 'swr' Helper(); const wilayah = dataWilayah(); const fetcher = (...args) => fetch(...args).then((res) => res.json()) function logTimestamp() { const now = new Date(); // Get the components of the date const year = now.getFullYear(); const month = (now.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based const day = now.getDate().toString().padStart(2, '0'); const hours = now.getHours().toString().padStart(2, '0'); const minutes = now.getMinutes().toString().padStart(2, '0'); const seconds = now.getSeconds().toString().padStart(2, '0'); // Create the timestamp string const timestamp = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // Log the timestamp return timestamp; } export default function PostListing({params}) { const [uniqid] = params.name; const { data: Listing } = useSWR(`/pages/api/produk?order=uniqid&ascdesc=DESC&limit=8&start=0&uniqid=${uniqid}`, fetcher) const route = useRouter(); const [price, setPrice] = useState(""); const [visible, setVisible] = useState(""); const [kota, setKota] = useState([]); const [kecamatan, setKecamatan] = useState([]); const [properti, setProperti] = useState("Dijual: Rumah & Apartement") const [hideTanah, setHideTanah] = useState(null) const [nilaiProperti, setNilaiProperty] = useState(null) const provinsiChange = function(event){ let getVal = event.target.value; let DataKota = wilayah.getGroupKota(getVal); setKota(DataKota); } const kotaChange = function(event){ let getVal = event.target.value; let dataKecamatan = wilayah.getGroupKecamatan(getVal); setKecamatan(dataKecamatan); } const data = [ { id: "01", text: "Dijual: Rumah & Apartement", status: 1, form: 'rumah' } ,{ id: "02", text: "Disewakan: Rumah & Apartement", status: 2, form:'rumah' } ,{ id: "03", text: "Tanah", status:'-', form:'tanah' } ,{ id: "04", text: "Indekos", status:0, form: 'indekos' } ,{ id: "05", text: "Dijual: Bangunan Komersil", status:1, form:'bangunan' } ,{ id: "07", text: "Disewakan: Bangunan Komersil", status:2, form:'bangunan' } ] function _id(id) { return document.getElementById(id); } const propertiChange = function(kode, data){ if(data){ let cek = dataStatus.cond(data.status, 'val'); if(cek.length > 0){ let {text} = cek[0]; let dataHidden = Array.from(document.querySelectorAll('div[data-hidden]')); dataHidden.forEach((c)=>{ c.style.display = 'none'; }) if (document.getElementById(text)){ document.getElementById(text).click(); } }else{ let dataHidden = Array.from(document.querySelectorAll('div[data-hidden]')); dataHidden.forEach((c)=>{ c.style.display = 'none'; }); } setProperti(data.nilai) hiddenForm(data) } } const hiddenForm = function(v){ if(v.nilai.toLowerCase().indexOf('rumah') == -1){ setHideTanah(1) }else{ setHideTanah(null) }; Array.from(document.querySelectorAll('div[data-shows]')) .forEach((dom)=>{ dom.dataset.shows.indexOf(v.form) != -1 ? dom.style.display = 'block' : dom.style.display = 'none'; }) v.nilai.toLowerCase() } function validasiProperty(v){ const formid = document.getElementById("formid"); const formData = new FormData(formid); const formProps = Object.fromEntries(formData); let fileds = ["lbangun", "ltanah", "ktidur", "kmandi", "hadap", "alamat", "judul", "deskrisi"]; if(formProps.slug2.toLowerCase().indexOf("tanah") != -1){ fileds = ["ltanah", "alamat", "judul", "deskrisi"]; } if(formProps.slug2.toLowerCase().indexOf("bangunan") != -1){ fileds = ["lbangun", "alamat", "judul", "hadap", "deskrisi"]; } if(formProps.slug2.toLowerCase().indexOf("indekos") != -1){ fileds = ["kmandi","alamat", "judul", "deskrisi"]; } let cek = 0; fileds.forEach((data)=>{ if(formProps[data] == ""){ cek++; } }); if(cek > 0){ backFunc(3); Array.from(document.querySelectorAll(".info-danger")) .forEach((h)=>{ h.style.display = 'block'; }) }else{ Array.from(document.querySelectorAll(".info-danger")) .forEach((h)=>{ h.style.display = 'none'; }) }; } function backFunc(a = 1, b = 6, nilai){ let activeBefore = a; for (let v = 1; v <= b; v++) { if(v == 2){ propertiChange(v, nilai) } if(a == v){ if (_id('kategori' + v)){ _id('kategori' + v).style.display = 'block'; } }else{ if (_id('kategori' + v)){ _id('kategori' + v).style.display = 'none'; } } } if(activeBefore == 4){ validasiProperty(3) } } useEffect(()=>{ if (Listing){ const [dataListing] = Listing.message; if(dataListing){ let prov = dataListing.prov; let kota = dataListing.kota; let kec = dataListing.kec; const dprovinsiChange = function (val) { let getVal = val; let DataKota = wilayah.getGroupKota(getVal); setKota(DataKota); } const dkotaChange = function (val) { let getVal = val; let dataKecamatan = wilayah.getGroupKecamatan(getVal); setKecamatan(dataKecamatan); } if(document.querySelector('select[name="prov"]')){ let nProv = document.querySelector('select[name="prov"]'); let nKota = document.querySelector('select[name="kota"]'); let nKec = document.querySelector('select[name="kec"]'); dprovinsiChange(prov) dkotaChange(kota) nProv.value = prov; setTimeout(function(){ nKota.value = kota; nKec.value = kec; },1000) } setPrice(dataListing.price ? dataListing.price:0); let getType = dataListing.slug2; let getData = data.filter(function (r) { if (r.text == getType) { return r; } }) .map(function (r) { return { form: r.form, nilai: r.text, status: r.status } }); let newProperty = getData.length > 0 ? getData[0] : null; backFunc(3, 6, newProperty) } } }, [Listing]); const summerChange = function(){ } const simpanData = async function(e){ e.preventDefault(); console.log("simpan") const formData = new FormData(e.target); const formProps = Object.fromEntries(formData); const image = Array.from(e.target.querySelectorAll('img')) let dataImage = []; if (formProps.judul === ""){ alert("judul tidak boleh kosong"); } if (formProps.judul === ""){ alert("judul tidak boleh kosong"); } image.map(function(w){ dataImage.push({ data: w.src, nama: w.alt }); }) let di = []; formProps.price = formProps.price.number(); formProps.galery = dataImage; formProps.facility = Array.from(document.querySelectorAll('input[name="facility"]')).map((r) => { return r.checked ? r.value : null; }).filter((r) => { if (r != null) { return r; } }).join(","); const ori = function () { let ori = location.host; if (ori == 'localhost:3000') { return 'https://app.rumahjo.com'; } if (ori == 'rumahjo.vercel.app') { return 'https://app.rumahjo.com'; } if (ori == 'rumahjo.com') { return 'https://app.rumahjo.com'; } return ''; } let dfacility = []; Array.from(e.target.querySelectorAll('[name="facility"]')) .forEach(function(o){ if(o.checked){ dfacility.push(o.value); } }) if(Listing.message){ let [dataListing] = Listing.message.length > 0 ? Listing.message : []; formProps.uniqid = dataListing.uniqid; formProps.update = true; formProps.userlog = logTimestamp(); formProps.approval = 0; } let validNumber = ['lbangun', 'ltanah', 'ktidur', 'kmandi', 'lantai', 'cert']; validNumber.forEach(function (s) { if (formProps[s] == "") { formProps[s] = 0; } }); let b64Data = btoa(JSON.stringify(formProps)); // validasi let fileds = ["prov", "kota", "kec"]; let cek = 0; fileds.forEach((data) => { if (formProps[data] == "") { cek++; } }); if (cek > 0) { alert("Pastikan lokasi sudah terisi dengan benar"); throw "stop upload"; } setVisible(!visible); upload(ori() + '/data/simpan/posting', '', 'qr.data', b64Data, (a) => { }, (b) => { route.push('/iklan'); setVisible(visible); }); } if(!Listing){ return <>
Rumahjo
} else{ const [listingData] = Listing.message; return (

Pasang Iklan Anda

Mau jual apa hari ini?

Properti

{data.map((q, i)=>{ return (
  • ) })}

    Include Some Details

    Upload Your Photos

    Set Your Price

    Price

    { let h = e.target.value.number().toString(); setPrice(h); }} type='text' name="price" className="bg-transparent text-right border-b py-2 pl-4 focus:outline-none focus:rounded-md focus:ring-1 ring-green-500 font-light text-gray-500" />

    Confirm Your Location

    Loading...
    ) } }