PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.8
Yatra – Travel Booking & Tour Operator Software v3.0.2.8
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / resources / js / components / ui / conditional-render.tsx

conditional-render.tsx in Yatra – Travel Booking & Tour Operator Software 3.0.2.8, at resources/js/components/ui/conditional-render.tsx

65 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Conditional Render Component
3 * Renders children based on permissions and Pro version status
4 * Supports extensibility for Pro version modifications
5 */
6
7 import React from "react";
8 import { usePermissions } from "../../hooks/usePermissions";
9
10 interface ConditionalRenderProps {
11 children: React.ReactNode;
12 capability?: string;
13 role?: string;
14 requirePro?: boolean;
15 fallback?: React.ReactNode;
16 className?: string;
17 }
18
19 /**
20 * Conditionally renders content based on permissions, roles, or Pro status
21 *
22 * @example
23 * <ConditionalRender capability="yatra_edit_trips">
24 * <EditButton />
25 * </ConditionalRender>
26 *
27 * @example
28 * <ConditionalRender requirePro fallback={<UpgradeMessage />}>
29 * <ProFeature />
30 * </ConditionalRender>
31 */
32 export const ConditionalRender: React.FC<ConditionalRenderProps> = ({
33 children,
34 capability,
35 role,
36 requirePro = false,
37 fallback = null,
38 className = "",
39 }) => {
40 const { can, hasRole, isPro } = usePermissions();
41
42 // Check if should render
43 let shouldRender = true;
44
45 if (capability && !can(capability)) {
46 shouldRender = false;
47 }
48
49 if (role && !hasRole(role)) {
50 shouldRender = false;
51 }
52
53 if (requirePro && !isPro) {
54 shouldRender = false;
55 }
56
57 if (!shouldRender) {
58 return <>{fallback}</>;
59 }
60
61 return <div className={className}>{children}</div>;
62 };
63
64 export default ConditionalRender;
65