React page not loading without error message

Viewed 18

After running it via npm, it doesn't work when I click on the page for the first time or type its extension, but when I click on other pages before clicking, page works. I deleted the string texts and imports. Footer navbar does not load either. The page is blank, only the background color appears.

Screenshots

const Profil = () => {
    const dataTableFuncMap = {
        products2: setProducts2,};
    
    const [date7, setDate7] = useState(null);
    const [totalSize, setTotalSize] = useState(0);
    const fileUploadRef = useRef(null);
    const [products, setProducts] = useState(null);
    const [products2, setProducts2] = useState(null);
    const [productDialog, setProductDialog] = useState(false);
    const [deleteProductDialog, setDeleteProductDialog] = useState(false);
    const [deleteProductsDialog, setDeleteProductsDialog] = useState(false);
    const [product, setProduct] = useState(emptyProduct);
    const [selectedProducts, setSelectedProducts] = useState(null);
    const [submitted, setSubmitted] = useState(false);
    const [globalFilter, setGlobalFilter] = useState(null);
    const toast = useRef(null);
    const dt = useRef(null);
    const [pzkapanıssaat, setPzkapanısssaat] = useState(null);
    const [ctkapanıssaat, setCtkapanısssaat] = useState(null);
    const [pzacılıssaat, setPzacılıssaat] = useState(null);
    const [ctacılıssaat, setCtacılıssaat] = useState(null);
    const [dkapanıssaat, setDkapanısssaat] = useState(null);
    const [dacılıssaat, setDacılıssaat] = useState(null);
    const [oacılıssaat, setOacılıssaat] = useState(null);
    const [okapanıssaat, setOkapanısssaat] = useState(null);
    const [otarih, setOtarih] = useState(null);
    const [editingRows, setEditingRows] = useState({});
    const productService = new ProductService();

    useEffect(() => {
        productService.getMagazalar().then((data) => setProducts(data));
        fetchProductData("products2");
    }, []);
    // eslint-disable-line react-hooks/exhaustive-deps

    const fetchProductData = (productStateKey) => {
        productService.getProductsSmall().then((data) => dataTableFuncMap[`${productStateKey}`](data));
    };
    const onRowEditComplete1 = (e) => {
        let _products2 = [...products2];
        let { newData, index } = e;
        _products2[index] = newData;
        setProducts2(_products2);
    };
        const textEditor = (options) => {
        return <InputText type="text" value={options.value} onChange={(e) => options.editorCallback(e.target.value)} />;};
        const statusEditor = (options) => {
        return (
            <Dropdown
                value={options.value}
                options={statuses}
                optionLabel="label"
                optionValue="value"
                onChange={(e) => options.editorCallback(e.value)}
                placeholder="Select a Status"
                itemTemplate={(option) => {
                    return <span className={`product-badge status-${option.value.toLowerCase()}`}>{option.label}</span>;
                }}/>); };

    const statusBodyTemplate = (rowData) => {
        return getStatusLabel(rowData.inventoryStatus);
    };

    const onTemplateSelect = (e) => {
        let _totalSize = totalSize;
        e.files.forEach((file) => {
            _totalSize += file.size;
        });

        setTotalSize(_totalSize);
    };

    const onTemplateUpload = (e) => {
        let _totalSize = 0;
        e.files.forEach((file) => {
            _totalSize += file.size || 0;
        });

        setTotalSize(_totalSize);
        toast.current.show({ severity: "info", summary: "Başarılı", detail: "Resim Yüklendi" });
    };

    const onTemplateRemove = (file, callback) => {
        setTotalSize(totalSize - file.size);
        callback();
    };

    const onTemplateClear = () => {
        setTotalSize(0);
    };

    const headerTemplate = (options) => {
        const { className, chooseButton, uploadButton, cancelButton } = options;
        const value = totalSize / 10000;
        const formatedValue = fileUploadRef && fileUploadRef.current ? fileUploadRef.current.formatSize(totalSize) : "0 B";

        return (
            <div className={className} style={{ backgroundColor: "transparent", display: "flex", alignItems: "center" }}>
                {chooseButton}
                {uploadButton}
                {cancelButton}
                <ProgressBar value={value} displayValueTemplate={() => `${formatedValue} / 1 MB`} style={{ width: "300px", height: "20px", marginLeft: "auto" }}></ProgressBar>
            </div>
        );
    };

    const itemTemplate = (file, props) => {
        return (
            <div className="flex align-items-center flex-wrap">
                <div className="flex align-items-center" style={{ width: "40%" }}>
                    <img alt={file.name} role="presentation" src={file.objectURL} width={100} />
                    <span className="flex flex-column text-left ml-3">
                        {file.name}
                        <small>{new Date().toLocaleDateString()}</small>
                    </span>
                </div>
                <Tag value={props.formatSize} severity="warning" className="px-3 py-2" />
                <Button type="button" icon="pi pi-times" className="p-button-outlined p-button-rounded p-button-danger ml-auto" onClick={() => onTemplateRemove(file, props.onRemove)} />
            </div>
        );
    };

    const emptyTemplate = () => {
        return (
            <div className="flex align-items-center flex-column">
                <i className="pi pi-image mt-3 p-5" style={{ fontSize: "5em", borderRadius: "50%", backgroundColor: "var(--surface-b)", color: "var(--surface-d)" }}></i>
                <span style={{ fontSize: "1.2em", color: "var(--text-color-secondary)" }} className="my-5">
                    Fotoğrafı Sürükle ve Bırak
                </span>
            </div>
        );
    };

    const openNew = () => {
        setProduct(emptyProduct);
        setSubmitted(false);
        setProductDialog(true);
    };

    const hideDialog = () => {
        setSubmitted(false);
        setProductDialog(false);
    };

    const hideDeleteProductDialog = () => {
        setDeleteProductDialog(false);
    };

    const hideDeleteProductsDialog = () => {
        setDeleteProductsDialog(false);
    };

    const saveProduct = () => {
        setSubmitted(true);

        if (product.name.trim()) {
            let _products = [...products];
            let _product = { ...product };
            if (product.id) {
                const index = findIndexById(product.id);

                _products[index] = _product;
                toast.current.show({ severity: "success", summary: "Başarılı", detail: "Mağaza Düzenlendi", life: 3000 });
            } else {
                _product.id = createId();
                _product.image = "product-placeholder.svg";
                _products.push(_product);
                toast.current.show({ severity: "success", summary: "Başarılı", detail: "Mağaza Oluşturuldu", life: 3000 });
            }

            setProducts(_products);
            setProductDialog(false);
            setProduct(emptyProduct);
        }
    };

    const editProduct = (product) => {
        setProduct({ ...product });
        setProductDialog(true);
    };

    const confirmDeleteProduct = (product) => {
        setProduct(product);
        setDeleteProductDialog(true);
    };
    const deleteProduct = () => {
        let _products = products.filter((val) => val.id !== product.id);
        setProducts(_products);
        setDeleteProductDialog(false);
        setProduct(emptyProduct);
        toast.current.show({ severity: "error", summary: "Başarılı", detail: "Mağaza Silindi", life: 3000 });
    };

    const findIndexById = (id) => {
        let index = -1;
        for (let i = 0; i < products.length; i++) {
            if (products[i].id === id) {
                index = i;
                break;
            }
        }

        return index;
    };

    const createId = () => {
        let id = "";
        let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for (let i = 0; i < 5; i++) {
            id += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        return id;
    };

    const exportCSV = () => {
        dt.current.exportCSV();
    };

    const confirmDeleteSelected = () => {
        setDeleteProductsDialog(true);
    };

    const deleteSelectedProducts = () => {
        let _products = products.filter((val) => !selectedProducts.includes(val));
        setProducts(_products);
        setDeleteProductsDialog(false);
        setSelectedProducts(null);
        toast.current.show({ severity: "error", summary: "Başarılı", detail: "Mağaza Silindi", life: 3000 });
    };

    const onCategoryChange = (e) => {
        let _product = { ...product };
        _product["category"] = e.value;
        setProduct(_product);
    };

    const onInputChange = (e, name) => {
        const val = (e.target && e.target.value) || "";
        let _product = { ...product };
        _product[`${name}`] = val;

        setProduct(_product);
    };

    const leftToolbarTemplate = () => {
        return (
            <React.Fragment>
                <div className=" my-2">
                    <Button label="Yeni Mağaza Ekle" icon="pi pi-plus" className="p-button-success mr-2" onClick={openNew} />
                    <Button label="Seçilen Mağazaları Sil" icon="pi pi-trash" className="p-button-danger" onClick={confirmDeleteSelected} disabled={!selectedProducts || !selectedProducts.length} />
                </div>
            </React.Fragment>
        );
    };

    const rightToolbarTemplate = () => {
        return (
            <React.Fragment>
                <FileUpload mode="basic" accept="image/*" maxFileSize={1000000} label="Import" chooseLabel="İçe Aktar" className="mr-2 inline-block" />
                <Button label="Dışa Aktar" icon="pi pi-upload" className="p-button-help" onClick={exportCSV} />
            </React.Fragment>
        );
    };

    const nameBodyTemplate = (rowData) => {
        return (
            <>
                <span className="p-column-title">Mağaza İsmi</span>
                {rowData.name}
            </>
        );
    };

    const imageBodyTemplate = (rowData) => {
        return (
            <>
                <span className="p-column-title">Görsel</span>
                <img src={`assets/demo/images/product/${rowData.image}`} alt={rowData.image} className="shadow-2" width="100" />
            </>
        );
    };

    const priceBodyTemplate = (rowData) => {
        return (
            <>
                <span className="p-column-title">Mağaza Detayı</span>
                {rowData.description}
            </>
        );
    };

    const categoryBodyTemplate = (rowData) => {
        return (
            <>
                <span className="p-column-title">Kategori</span>
                {rowData.category}
            </>
        );
    };

    const actionBodyTemplate = (rowData) => {
        return (
            <div className="actions">
                <Button icon="pi pi-pencil" className="p-button-rounded p-button-success mr-2" onClick={() => editProduct(rowData)} />
                <Button icon="pi pi-trash" className="p-button-rounded p-button-danger mt-2" onClick={() => confirmDeleteProduct(rowData)} />
            </div>
        );
    };

    const productDialogFooter = (
        <React.Fragment>
            <Button label="İptal" icon="pi pi-times" className="p-button-text" onClick={hideDialog} />
            <Button label="Kaydet" icon="pi pi-check" className="p-button-text" onClick={saveProduct} />
        </React.Fragment>
    );
    const deleteProductDialogFooter = (
        <React.Fragment>
            <Button label="Hayır" icon="pi pi-times" className="p-button-text" onClick={hideDeleteProductDialog} />
            <Button label="Evet" icon="pi pi-check" className="p-button-text" onClick={deleteProduct} />
        </React.Fragment>
    );
    const deleteProductsDialogFooter = (
        <React.Fragment>
            <Button label="Hayır" icon="pi pi-times" className="p-button-text" onClick={hideDeleteProductsDialog} />
            <Button label="Evet" icon="pi pi-check" className="p-button-text" onClick={deleteSelectedProducts} />
        </React.Fragment>
    );
    const header = (
        <div className="table-header">
            <span className="p-input-icon-left">
                <i className="pi pi-search" />
                <InputText type="search" onInput={(e) => setGlobalFilter(e.target.value)} placeholder="Arama..." />
            </span>
        </div>
    );

    const chooseOptions = { icon: "pi pi-fw pi-images", iconOnly: true, className: "custom-choose-btn p-button-rounded p-button-outlined w-3rem" };
    const uploadOptions = { icon: "pi pi-fw pi-cloud-upload", iconOnly: true, className: "custom-upload-btn p-button-success p-button-rounded p-button-outlined w-3rem" };
    const cancelOptions = { icon: "pi pi-fw pi-times", iconOnly: true, className: "custom-cancel-btn p-button-danger p-button-rounded p-button-outlined w-3rem" };

    return (
        <div className="grid">
            <div className="col-12">
                <div className="card">
                    <div className="flex overflow-hidden">
                        <div className="flex-none flex align-items-center justify-content-center mx-0 my-2 px-5 py-3 ">
                            <Image src="\assets\layout\images\indir.png" alt="Image" width="150" preview />
                        </div>
                        <div className="flex-grow-1 flex align-items-center justify-content-center mx-0 my-2 px-0 py-3 overflow-hidden">
                            <h1>Panora AVM</h1>
                        </div>
                        <div className="flex-none flex align-items-center justify-content-center mx-0 my-2 px-5 py-3 ">
                            <Button label="Çıkış Yap" icon="pi pi-sign-out" className="p-button-danger" />
                        </div>
                    </div>
                </div>
            </div>
            <div className="col-6">
                <div className="card">
                    <h5>Düzenli Çalışma Saatleri</h5>
                    <div className="grid">
                        <div className="col-4">
                            <label htmlFor="time24">Haftaiçi</label>
                        </div>
                        <div className="col-4">
                            <Calendar id="time24" value={dacılıssaat} onChange={(e) => setDacılıssaat(e.value)} showTime showSeconds />
                        </div>
                        <div className="col-4">
                            <Calendar id="time24" value={dkapanıssaat} onChange={(e) => dkapanıssaat(e.value)} showTime showSeconds />
                        </div>
                        <div className="col-4">
                            <label htmlFor="time24">Cumartesi</label>
                        </div>
                        <div className="col-4">
                            <Calendar id="time24" value={ctacılıssaat} onChange={(e) => setCtacılıssaat(e.value)} showTime showSeconds />
                        </div>
                        <div className="col-4">
                            <Calendar id="time24" value={ctkapanıssaat} onChange={(e) => setCtkapanısssaat(e.value)} showTime showSeconds />
                        </div>
                        <div className="col-4">
                            <label htmlFor="time24">Pazar</label>
                        </div>
                        <div className="col-4">
                            <Calendar id="time24" value={pzacılıssaat} onChange={(e) => setPzacılıssaat(e.value)} showTime showSeconds />
                        </div>
                        <div className="col-4">
                            <Calendar id="time24" value={pzkapanıssaat} onChange={(e) => setPzkapanısssaat(e.value)} showTime showSeconds />
                        </div>
                    </div>
                </div>
            </div>
            <div className="col-6">
                <div className="card">
                    <h5>Özel Günler Çalışma Saatleri</h5>
                    <div className="grid">
                        <div className="col-2 mt-4 align-items-center justify-content-center">
                            <label htmlFor="calendar">Açılış</label>
                        </div>
                        <div className="col-3 mt-3 mr-8">
                            <Calendar id="oacılıssaat" timeOnly value={oacılıssaat} locale="tr" onChange={(e) => setOacılıssaat(e.value)} selectionMode="range" showWeek />
                        </div>
                        <div className="col-2 mt-4 ml-2 align-items-center justify-content-center">
                            <label htmlFor="calendar">Kapanış</label>
                        </div>
                        <div className="col-3 mt-3">
                            <Calendar id="okapanıssaat" timeOnly value={okapanıssaat} locale="tr" onChange={(e) => setOkapanısssaat(e.value)} selectionMode="range" showWeek />
                        </div>
                        <div className="col-2 mt-4 align-items-center justify-content-center">
                            <label htmlFor="calendar">Tarihler</label>
                        </div>
                        <div className="col-3 mt-3">
                            <Calendar id="calendar" value={otarih} locale="tr" onChange={(e) => setOtarih(e.value)} selectionMode="range" showWeek />
                        </div>
                        <div className="col-7 flex flex-wrap align-items-center justify-content-end">
                            <Button label="Kaydet" className="p-button flex h-3rem align-items-center justify-content-center" icon="pi pi-check" iconPos="right" />
                        </div>
                        <div className="col-12">
                            <label>Row Editing</label>
                            <DataTable value={products2} editMode="row" dataKey="id" onRowEditComplete={onRowEditComplete1} responsiveLayout="scroll">
                                <Column field="code" header="Tarih" editor={(options) => textEditor(options)} style={{ width: "20%" }}></Column>
                                <Column field="name" header="Açılış" editor={(options) => textEditor(options)} style={{ width: "20%" }}></Column>
                                <Column field="inventoryStatus" header="Kapanış" body={statusBodyTemplate} editor={(options) => statusEditor(options)} style={{ width: "20%" }}></Column>
                                <Column rowEditor headerStyle={{ width: "10%", minWidth: "8rem" }} bodyStyle={{ textAlign: "center" }}></Column>
                            </DataTable>
                        </div>
                    </div>
                </div>
            </div>
            <div className="col-12">
                <div className="card">
                    <Toast ref={toast} />
                    <h5>Mağaza Listesi</h5>
                    <Toolbar className="my-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar>

                    <DataTable
                        ref={dt}
                        value={products}
                        selection={selectedProducts}
                        onSelectionChange={(e) => setSelectedProducts(e.value)}
                        dataKey="id"
                        paginator
                        rows={10}
                        rowsPerPageOptions={[5, 10, 25]}
                        className="datatable-responsive justify-content-center"
                        paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
                        currentPageReportTemplate="{totalRecords} mağazadan {first} ila {last} tanesi gösteriliyor"
                        globalFilter={globalFilter}
                        emptyMessage="Mağaza bulunamadı."
                        responsiveLayout="scroll"
                        header={header}
                    >
                        <Column selectionMode="multiple" headerStyle={{ width: "3rem" }}></Column>
                        <Column field="name" header="Mağaza İsmi" sortable body={nameBodyTemplate} align={"center"} headerStyle={{ width: "14%", minWidth: "10rem" }}></Column>
                        <Column header="Görsel" body={imageBodyTemplate} align={"center"} headerStyle={{ width: "14%", minWidth: "10rem" }}></Column>
                        <Column field="price" header="Mağaza Detayı" body={priceBodyTemplate} sortable align={"center"} headerStyle={{ width: "30%", minWidth: "8rem" }}></Column>
                        <Column field="category" header="Kategori" align={"center"} sortable body={categoryBodyTemplate} headerStyle={{ width: "20%", minWidth: "10rem" }}></Column>
                        <Column body={actionBodyTemplate}></Column>
                    </DataTable>

                    <Dialog visible={productDialog} style={{ width: "450px" }} header="Mağaza Düzenle" modal className="p-fluid" footer={productDialogFooter} onHide={hideDialog}>
                        {(product.image && (
                            <span className="flex align-items-center justify-content-center pb-3 m-auto">
                                <Image src={`assets/demo/images/product/${product.image}`} onError={(e) => (e.target.src = "https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png")} alt={product.image} preview />
                            </span>
                        )) ||
                            (!product.image && (
                                <div className="grid">
                                    <div className="col-12 w-full">
                                        <FileUpload
                                            ref={fileUploadRef}
                                            name="demo[]"
                                            url="https://primefaces.org/primereact/showcase/upload.php"
                                            multiple
                                            accept="image/*"
                                            maxFileSize={1000000}
                                            onUpload={onTemplateUpload}
                                            onSelect={onTemplateSelect}
                                            onError={onTemplateClear}
                                            onClear={onTemplateClear}
                                            headerTemplate={headerTemplate}
                                            itemTemplate={itemTemplate}
                                            emptyTemplate={emptyTemplate}
                                            chooseOptions={chooseOptions}
                                            uploadOptions={uploadOptions}
                                            cancelOptions={cancelOptions}
                                        />
                                    </div>
                                </div>
                            ))}
                        <div className="field">
                            <label htmlFor="name">Mağaza İsmi</label>
                            <InputText id="name" value={product.name} onChange={(e) => onInputChange(e, "name")} required autoFocus className={classNames({ "p-invalid": submitted && !product.name })} />
                            {submitted && !product.name && <small className="p-invalid">İsim alanı zorunludur.</small>}
                        </div>
                        <div className="field">
                            <label htmlFor="description">Mağaza Detayları</label>
                            <InputTextarea id="description" value={product.description} onChange={(e) => onInputChange(e, "description")} required rows={3} cols={20} />
                        </div>

                        <div className="field">
                            <label className="mb-3">Kategori</label>
                            <div className="formgrid grid">
                                <div className="field-radiobutton col-6">
                                    <RadioButton inputId="category1" name="category" value="Aksesuar" onChange={onCategoryChange} checked={product.category === "Aksesuar"} />
                                    <label htmlFor="category1">Aksesuar</label>
                                </div>
                                <div className="field-radiobutton col-6">
                                    <RadioButton inputId="category2" name="category" value="Giyim" onChange={onCategoryChange} checked={product.category === "Giyim"} />
                                    <label htmlFor="category2">Giyim</label>
                                </div>
                                <div className="field-radiobutton col-6">
                                    <RadioButton inputId="category3" name="category" value="Elektronik" onChange={onCategoryChange} checked={product.category === "Elektronik"} />
                                    <label htmlFor="category3">Elektronik</label>
                                </div>
                                <div className="field-radiobutton col-6">
                                    <RadioButton inputId="category4" name="category" value="Spor & Eğlence" onChange={onCategoryChange} checked={product.category === "Spor & Eğlence"} />
                                    <label htmlFor="category4">Spor & Eğlence</label>
                                </div>
                            </div>
                        </div>
                    </Dialog>

                    <Dialog visible={deleteProductDialog} draggable={false} style={{ width: "450px" }} header="Onayla" modal footer={deleteProductDialogFooter} onHide={hideDeleteProductDialog}>
                        <div className="confirmation-content">
                            <i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: "2rem" }} />
                            {product && <span>Mağazayı silmek istediğinize emin misiniz ?</span>}
                        </div>
                    </Dialog>

                    <Dialog visible={deleteProductsDialog} draggable={false} style={{ width: "450px" }} header="Onayla" modal footer={deleteProductsDialogFooter} onHide={hideDeleteProductsDialog}>
                        <div className="confirmation-content">
                            <i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: "2rem" }} />
                            {product && <span>Seçilen mağazayı silmek istediğinize emin misiniz?</span>}
                        </div>
                    </Dialog>
                </div>
            </div>
        </div>
    );
};

const comparisonFn = function (prevProps, nextProps) {
    return prevProps.location.pathname === nextProps.location.pathname;
};

export default React.memo(Profil, comparisonFn);
0 Answers
Related