Skip to content

Commit

Permalink
Conditional template rendering and react router done.
Browse files Browse the repository at this point in the history
  • Loading branch information
shohag121 authored and Aunshon committed Jan 15, 2025
1 parent 754b010 commit b91b8dd
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 34 deletions.
5 changes: 3 additions & 2 deletions docs/feature-override/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[//]: # (TODO: Update the document with the correct information and hook name.)
# How to define a menu is available in `React` and its `PHP` override information.

- [Introduction](#introduction)
Expand Down Expand Up @@ -153,9 +154,9 @@ If you did not override any of the template file directly but you have override

```php

add_filter( 'dokan_is_dashboard_nav_dependency_cleared', function ( $is_cleared, $route ) {
add_filter( 'dokan_is_dashboard_nav_dependency_resolved', function ( $is_cleared, $route ) {
if ( 'products' === $route ) {
return true;
return false;
}

return $is_cleared;
Expand Down
12 changes: 2 additions & 10 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace WeDevs\Dokan;

use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
use WeDevs\Dokan\Admin\Notices\Helper;
use WeDevs\Dokan\ReverseWithdrawal\SettingsHelper;
use WeDevs\Dokan\ProductCategory\Helper as CategoryHelper;
Expand All @@ -16,11 +15,6 @@ class Assets {
public function __construct() {
add_action( 'init', [ $this, 'register_all_scripts' ], 10 );
add_filter( 'dokan_localized_args', [ $this, 'conditional_localized_args' ] );
add_action(
'wp_footer', function () {
echo '<div class="dokan-layout" id="headlessui-portal-root"><div></div></div>';
}
);

if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ], 10 );
Expand Down Expand Up @@ -661,7 +655,8 @@ public function enqueue_front_scripts() {
'routeComponents' => [ 'default' => null ],
'routes' => $this->get_vue_frontend_routes(),
'urls' => [
'assetsUrl' => DOKAN_PLUGIN_ASSEST,
'assetsUrl' => DOKAN_PLUGIN_ASSEST,
'dashboardUrl' => dokan_get_navigation_url(),
],
]
);
Expand Down Expand Up @@ -889,9 +884,6 @@ public function dokan_dashboard_scripts() {
self::load_form_validate_script();
$this->load_gmap_script();

$wc_instance = WCAdminAssets::get_instance();
$wc_instance->register_scripts();

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
Expand Down
36 changes: 36 additions & 0 deletions includes/Dashboard/Templates/NewDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

namespace WeDevs\Dokan\Dashboard\Templates;

use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;

class NewDashboard {

/**
* Class constructor
*
* @since DOKAN_SINCE
*/
public function __construct() {
add_filter(
'dokan_query_var_filter',
Expand All @@ -21,11 +28,30 @@ public function __construct() {
);
}

/**
* Add query var for new dashboard.
*
* @since DOKAN_SINCE
*
* @param array $query_vars
*
* @return array
*/
public function add_query_var( $query_vars ) {
$query_vars['new'] = 'new';
return $query_vars;
}


/**
* Load new dashboard content.
*
* @since DOKAN_SINCE
*
* @param array $query_vars
*
* @return void
*/
public function new_dashboard_content( $query_vars ) {
if ( isset( $query_vars['new'] ) ) {
if ( ! current_user_can( 'dokan_view_overview_menu' ) ) {
Expand All @@ -36,12 +62,22 @@ public function new_dashboard_content( $query_vars ) {
}
}

/**
* Enqueue scripts for new dashboard.
*
* @since DOKAN_SINCE
*
* @return void
*/
public function enqueue_scripts() {
global $wp;
if ( ! dokan_is_seller_dashboard() || ! isset( $wp->query_vars['new'] ) ) {
return;
}

$wc_instance = WCAdminAssets::get_instance();
$wc_instance->register_scripts();

wp_enqueue_script( 'dokan-react-frontend' );
wp_enqueue_style( 'dokan-react-frontend' );
}
Expand Down
52 changes: 30 additions & 22 deletions src/Layout/404.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import { __ } from "@wordpress/i18n";
import { __ } from '@wordpress/i18n';

const NotFound = () => {
return (
<div className="text-center">
<p className="text-lg font-semibold text-indigo-600">{ __( '404', 'dokan-lite' ) }</p>
<h1 className="mt-4 text-balance text-5xl font-semibold tracking-tight text-gray-900 sm:text-7xl">
{ __( 'Page not found', 'dokan-lite' ) }
</h1>
<p className="mt-6 text-pretty text-lg font-medium text-gray-500 sm:text-xl/8">
{ __( 'Sorry, we couldn’t find the page you’re looking for.', 'dokan-lite' ) }
</p>
<div className="mt-10 flex items-center justify-center gap-x-6">
<a
href="#"
className="rounded-md bg-dokan-btn px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-dokan-btn-hover focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
{ __( 'Go back home', 'dokan-lite' ) }
</a>
</div>
</div>
);
}
const NotFound = () => {
// @ts-ignore
const dashBoardUrl = window.dokan?.urls?.dashboardUrl ?? '#';

return (
<div className="text-center">
<p className="text-lg font-semibold text-indigo-600">
{ __( '404', 'dokan-lite' ) }
</p>
<h1 className="mt-4 text-balance text-5xl font-semibold tracking-tight text-gray-900 sm:text-7xl">
{ __( 'Page not found', 'dokan-lite' ) }
</h1>
<p className="mt-6 text-pretty text-lg font-medium text-gray-500 sm:text-xl/8">
{ __(
'Sorry, we couldn’t find the page you’re looking for.',
'dokan-lite'
) }
</p>
<div className="mt-10 flex items-center justify-center gap-x-6">
<a
href={ dashBoardUrl }
className="rounded-md bg-dokan-btn px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-dokan-btn-hover focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
{ __( 'Go back home', 'dokan-lite' ) }
</a>
</div>
</div>
);
};

export default NotFound;
2 changes: 2 additions & 0 deletions templates/dashboard/new-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@
</div><!-- .dokan-dashboard-wrap -->

<?php do_action( 'dokan_dashboard_wrap_end' ); ?>

<div class="dokan-layout" id="headlessui-portal-root"><div></div></div>

0 comments on commit b91b8dd

Please sign in to comment.