Skip to content

Commit

Permalink
Rename variables and ensure they're accessible once config cached
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Jun 6, 2024
1 parent 37689ab commit 1482054
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
15 changes: 5 additions & 10 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ public function share(Request $request): array
{
return array_merge(parent::share($request), [
'config' => [
'VITE_PUSHER_APP_KEY' => env('VITE_PUSHER_APP_KEY'),
'VITE_PUSHER_HOST' => env('VITE_PUSHER_HOST'),
'VITE_PUSHER_PORT' => env('VITE_PUSHER_PORT'),
'VITE_PUSHER_SCHEME' => env('VITE_PUSHER_SCHEME'),
'VITE_PUSHER_APP_CLUSTER' => env('VITE_PUSHER_APP_CLUSTER'),
'VITE_APP_ENV' => env('VITE_APP_ENV'),
'VITE_SENTRY_DSN' => env('VITE_SENTRY_DSN'),
'VITE_SENTRY_ENABLED' => env('VITE_SENTRY_ENABLED'),
'VITE_UITID_WIDGET_URL' => env('VITE_UITID_WIDGET_URL'),
'VITE_UITPAS_INTEGRATION_TYPE_ENABLED' => env('VITE_UITPAS_INTEGRATION_TYPE_ENABLED'),
'env' => config('app.env'),
'sentryDsn' => config('sentry.dsn'),
'sentryEnabled' => config('app.sentry.enabled'),
'uitpasEnabled' => config('uitpas.enabled')
],
'widgetConfig' => [
'url' => config('uitidwidget.url'),
'profileUrl' => config('uitidwidget.profileUrl'),
'registerUrl' => config('uitidwidget.registerUrl'),
'auth0Domain' => config('uitidwidget.auth0Domain'),
Expand Down
1 change: 1 addition & 0 deletions config/uitidwidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

return [
'url' => env('UITID_WIDGET_URL'),
'profileUrl' => env('UITID_WIDGET_PROFILE_URL'),
'registerUrl' => env('UITID_WIDGET_REGISTER_URL'),
'auth0Domain' => env('UITID_WIDGET_AUTH0_DOMAIN'),
Expand Down
4 changes: 2 additions & 2 deletions resources/ts/Components/IntegrationTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const useIntegrationTypesInfo = () => {
const integrationTypesInfo = getIntegrationTypesInfo(t);

// See https://jira.publiq.be/browse/PPF-481
return config.VITE_UITPAS_INTEGRATION_TYPE_ENABLED
return config.uitpasEnabled
? integrationTypesInfo
: integrationTypesInfo.filter(
(integrationTypesInfo) =>
Expand All @@ -101,7 +101,7 @@ export type IntegrationTypesInfo = ReturnType<
export const IntegrationTypes = () => {
const config = useRuntimeConfig();
const filteredIntegrationTypes = useIntegrationTypesInfo();
const uitpasEnabled = config.VITE_UITPAS_INTEGRATION_TYPE_ENABLED;
const uitpasEnabled = config.uitpasEnabled;

return (
<div>
Expand Down
6 changes: 3 additions & 3 deletions resources/ts/Components/UitIdWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Integration } from "../types/Integration";
import type { PageProps, WidgetConfigVariables } from "../types/PageProps";

export const UitIdWidget = ({
url,
profileUrl,
registerUrl,
auth0Domain,
Expand All @@ -20,11 +21,10 @@ export const UitIdWidget = ({
}
>();

const widgetUrl = props.config.VITE_UITID_WIDGET_URL;
const widgetConfig = useMemo(
() =>
JSON.stringify({
$schema: `${widgetUrl}config-schema.json`,
$schema: `${url}config-schema.json`,
applicationName: "publiq platform",
uitidProfileUrl: profileUrl,
uitidRegisterUrl: registerUrl,
Expand All @@ -47,7 +47,7 @@ export const UitIdWidget = ({
},
],
}),
[auth0Domain, profileUrl, registerUrl, widgetUrl]
[auth0Domain, profileUrl, registerUrl, url]
);

const currentPage = useMemo(
Expand Down
6 changes: 3 additions & 3 deletions resources/ts/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ createInertiaApp<PageProps>({
const config = props.initialPage.props.config;

Sentry.init({
dsn: config.VITE_SENTRY_DSN,
environment: config.VITE_APP_ENV,
enabled: config.VITE_SENTRY_ENABLED,
dsn: config.sentryDsn,
environment: config.env,
enabled: config.sentryEnabled,
});

initializeI18n().then(() => {
Expand Down
9 changes: 6 additions & 3 deletions resources/ts/layouts/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ const Main = ({ children }: { children: ReactNode }) => (
);

export default function Layout({ children }: { children: ReactNode }) {
const { widgetConfig, config } = usePage<PageProps>().props;
const widgetUrl = config.VITE_UITID_WIDGET_URL;
const { widgetConfig } = usePage<PageProps>().props;

return (
<div className="flex flex-col flex-1 items-center text-publiq-gray-900 bg-publiq-gray-75">
<Head>
<script type="module" src={`${widgetUrl}index.js`} async></script>
<script
type="module"
src={`${widgetConfig.url}index.js`}
async
></script>
</Head>

<UitIdWidget {...widgetConfig} />
Expand Down
5 changes: 3 additions & 2 deletions resources/ts/types/PageProps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export type WidgetConfigVariables = {
url: string;
profileUrl: string;
registerUrl: string;
auth0Domain: string;
};
export type PageProps = {
widgetConfig: WidgetConfigVariables;
config: { [key: string]: string } & {
VITE_SENTRY_ENABLED: boolean;
VITE_UITPAS_INTEGRATION_TYPE_ENABLED: boolean;
sentryEnabled: boolean;
uitpasEnabled: boolean;
};
};

0 comments on commit 1482054

Please sign in to comment.