uibee 2.8.5 → 2.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,10 +83,32 @@ export default function Input(props) {
83
83
  const date = new Date(value);
84
84
  return isNaN(date.getTime()) ? null : date;
85
85
  }
86
+ function getDateDisplayValue() {
87
+ if (!value || !isDateType)
88
+ return value;
89
+ const date = getDateValue();
90
+ if (!date)
91
+ return value;
92
+ function pad(n) {
93
+ return n.toString().padStart(2, '0');
94
+ }
95
+ const yyyy = date.getFullYear();
96
+ const MM = pad(date.getMonth() + 1);
97
+ const dd = pad(date.getDate());
98
+ const hh = pad(date.getHours());
99
+ const mm = pad(date.getMinutes());
100
+ if (type === 'date')
101
+ return `${dd}.${MM}.${yyyy}`;
102
+ if (type === 'time')
103
+ return `${hh}:${mm}`;
104
+ if (type === 'datetime-local')
105
+ return `${dd}.${MM}.${yyyy} ${hh}:${mm}`;
106
+ return value;
107
+ }
86
108
  return (_jsx(FieldWrapper, { label: label, name: name, required: inputProps.required, info: info, error: error, className: className, children: _jsxs("div", { className: 'relative flex items-center', ref: containerRef, children: [displayIcon && (_jsx("div", { className: `
87
109
  absolute left-3 text-login-200
88
110
  ${isClickableType && !inputProps.disabled ? 'cursor-pointer hover:text-login-text' : 'pointer-events-none'}
89
- `, onClick: handleIconClick, children: displayIcon })), _jsx("input", { ...inputProps, ref: localRef, id: name, name: name, type: isClickableType ? 'text' : type, value: value, readOnly: isClickableType, onClick: () => isClickableType && !inputProps.disabled && setIsOpen(true), title: label, "aria-invalid": !!error, "aria-describedby": error ? `${name}-error` : undefined, className: `
111
+ `, onClick: handleIconClick, children: displayIcon })), _jsx("input", { ...inputProps, ref: localRef, id: name, name: isClickableType ? undefined : name, type: isClickableType ? 'text' : type, value: isDateType ? getDateDisplayValue() : value, readOnly: isClickableType, onClick: () => isClickableType && !inputProps.disabled && setIsOpen(true), title: label, "aria-invalid": !!error, "aria-describedby": error ? `${name}-error` : undefined, className: `
90
112
  w-full rounded-md bg-login-500/50 border border-login-500
91
113
  text-login-text placeholder-login-200
92
114
  focus:outline-none focus:border-login focus:ring-1 focus:ring-login
@@ -96,5 +118,5 @@ export default function Input(props) {
96
118
  input-reset
97
119
  ${error ? 'border-red-500 focus:border-red-500 focus:ring-red-500' : ''}
98
120
  ${isClickableType && !inputProps.disabled ? 'cursor-pointer' : ''}
99
- ` }), isOpen && isDateType && !inputProps.disabled && (_jsx(DateTimePickerPopup, { value: getDateValue(), onChange: handleDateChange, type: type, onClose: () => setIsOpen(false) })), isOpen && isColorType && !inputProps.disabled && (_jsx(ColorPickerPopup, { value: value || '', onChange: handleColorChange, onClose: () => setIsOpen(false) }))] }) }));
121
+ ` }), isClickableType && (_jsx("input", { type: 'hidden', name: name, value: value })), isOpen && isDateType && !inputProps.disabled && (_jsx(DateTimePickerPopup, { value: getDateValue(), onChange: handleDateChange, type: type, onClose: () => setIsOpen(false) })), isOpen && isColorType && !inputProps.disabled && (_jsx(ColorPickerPopup, { value: value || '', onChange: handleColorChange, onClose: () => setIsOpen(false) }))] }) }));
100
122
  }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState, useEffect } from 'react';
3
3
  import { ChevronLeft, ChevronRight } from 'lucide-react';
4
- const DAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
4
+ const DAYS = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
5
5
  const MONTHS = [
6
6
  'January', 'February', 'March', 'April', 'May', 'June',
7
7
  'July', 'August', 'September', 'October', 'November', 'December'
@@ -87,7 +87,8 @@ export default function DateTimePickerPopup({ value, onChange, type, onClose, })
87
87
  const daysInMonth = getDaysInMonth(year, month);
88
88
  const firstDay = getFirstDayOfMonth(year, month);
89
89
  const days = [];
90
- for (let i = 0; i < firstDay; i++) {
90
+ const adjustedFirstDay = firstDay === 0 ? 6 : firstDay - 1;
91
+ for (let i = 0; i < adjustedFirstDay; i++) {
91
92
  days.push(_jsx("div", { className: 'w-8 h-8' }, `empty-${i}`));
92
93
  }
93
94
  for (let i = 1; i <= daysInMonth; i++) {
@@ -1,2 +1,2 @@
1
1
  import type { AuthCallbackProps } from 'uibee/utils';
2
- export default function authCallback({ req, tokenURL, clientID, clientSecret, redirectURL, userInfoURL, tokenRedirectURL }: AuthCallbackProps): Promise<Response>;
2
+ export default function authCallback({ req, tokenURL, clientID, clientSecret, redirectPath, userInfoURL, tokenRedirectPath }: AuthCallbackProps): Promise<Response>;
@@ -1,5 +1,7 @@
1
1
  import { NextResponse } from 'next/server';
2
- export default async function authCallback({ req, tokenURL, clientID, clientSecret, redirectURL, userInfoURL, tokenRedirectURL }) {
2
+ import { getDomain } from './getDomain';
3
+ export default async function authCallback({ req, tokenURL, clientID, clientSecret, redirectPath, userInfoURL, tokenRedirectPath }) {
4
+ const domain = getDomain(req);
3
5
  const searchParams = new URL(req.url).searchParams;
4
6
  if (!searchParams) {
5
7
  return NextResponse.json({ error: 'No search parameters found.' }, { status: 400 });
@@ -17,7 +19,7 @@ export default async function authCallback({ req, tokenURL, clientID, clientSecr
17
19
  client_id: clientID,
18
20
  client_secret: clientSecret,
19
21
  code: code,
20
- redirect_uri: redirectURL,
22
+ redirect_uri: `${domain}${redirectPath}`,
21
23
  grant_type: 'authorization_code',
22
24
  }).toString()
23
25
  });
@@ -41,7 +43,7 @@ export default async function authCallback({ req, tokenURL, clientID, clientSecr
41
43
  });
42
44
  }
43
45
  const userInfo = await userInfoResponse.json();
44
- const redirectUrl = new URL(tokenRedirectURL);
46
+ const redirectUrl = new URL(`${domain}${tokenRedirectPath}`);
45
47
  const params = new URLSearchParams({
46
48
  id: userInfo.sub,
47
49
  name: userInfo.name,
@@ -0,0 +1,2 @@
1
+ import { NextRequest } from 'next/server';
2
+ export declare function getDomain(req: NextRequest): string;
@@ -0,0 +1,5 @@
1
+ export function getDomain(req) {
2
+ const proto = req.headers.get('x-forwarded-proto') ?? new URL(req.url).protocol.replace(':', '');
3
+ const host = req.headers.get('x-forwarded-host') ?? req.headers.get('host') ?? new URL(req.url).host;
4
+ return `${proto}://${host}`;
5
+ }
@@ -1,3 +1,3 @@
1
1
  import { NextResponse } from 'next/server';
2
2
  import type { AuthLoginProps } from 'uibee/utils';
3
- export default function AuthLogin({ clientID, redirectURL, authURL }: AuthLoginProps): Promise<NextResponse<unknown>>;
3
+ export default function AuthLogin({ req, clientID, redirectPath, authURL }: AuthLoginProps): Promise<NextResponse<unknown>>;
@@ -1,9 +1,11 @@
1
1
  import { NextResponse } from 'next/server';
2
- export default async function AuthLogin({ clientID, redirectURL, authURL }) {
2
+ import { getDomain } from './getDomain';
3
+ export default async function AuthLogin({ req, clientID, redirectPath, authURL }) {
4
+ const domain = getDomain(req);
3
5
  const state = Math.random().toString(36).substring(5);
4
6
  const authQueryParams = new URLSearchParams({
5
7
  client_id: clientID,
6
- redirect_uri: redirectURL,
8
+ redirect_uri: `${domain}${redirectPath}`,
7
9
  response_type: 'code',
8
10
  scope: 'openid profile email',
9
11
  state: state,
@@ -1,3 +1,3 @@
1
1
  import { NextResponse } from 'next/server';
2
2
  import type { AuthLogoutProps } from 'uibee/utils';
3
- export default function AuthLogout({ frontendURL, path }: AuthLogoutProps): Promise<NextResponse<unknown>>;
3
+ export default function AuthLogout({ req, path }: AuthLogoutProps): Promise<NextResponse<unknown>>;
@@ -1,6 +1,8 @@
1
1
  import { NextResponse } from 'next/server';
2
- export default async function AuthLogout({ frontendURL, path }) {
3
- const response = NextResponse.redirect(new URL(path || '/', frontendURL));
2
+ import { getDomain } from './getDomain';
3
+ export default async function AuthLogout({ req, path }) {
4
+ const domain = getDomain(req);
5
+ const response = NextResponse.redirect(new URL(path || '/', domain));
4
6
  const cookiesToRemove = [
5
7
  'access_token',
6
8
  'user_id',
@@ -1,3 +1,3 @@
1
1
  import { NextResponse } from 'next/server';
2
2
  import type { AuthTokenProps } from 'uibee/utils';
3
- export default function AuthToken({ req, frontendURL, redirectPath }: AuthTokenProps): Promise<NextResponse<unknown>>;
3
+ export default function AuthToken({ req, redirectPath }: AuthTokenProps): Promise<NextResponse<unknown>>;
@@ -1,5 +1,7 @@
1
1
  import { NextResponse } from 'next/server';
2
- export default async function AuthToken({ req, frontendURL, redirectPath }) {
2
+ import { getDomain } from './getDomain';
3
+ export default async function AuthToken({ req, redirectPath }) {
4
+ const domain = getDomain(req);
3
5
  const url = new URL(req.url);
4
6
  const token = url.searchParams.get('access_token');
5
7
  const btg = url.searchParams.get('btg');
@@ -9,7 +11,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }) {
9
11
  return NextResponse.json({ error: 'No access token provided' }, { status: 400 });
10
12
  }
11
13
  if (btg) {
12
- return NextResponse.redirect(new URL(redirect, frontendURL));
14
+ return NextResponse.redirect(new URL(redirect, domain));
13
15
  }
14
16
  const accessToken = url.searchParams.get('access_token');
15
17
  const userID = url.searchParams.get('id');
@@ -17,7 +19,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }) {
17
19
  const userNickname = url.searchParams.get('username');
18
20
  const userEmail = url.searchParams.get('email');
19
21
  const userGroups = url.searchParams.get('groups');
20
- const response = NextResponse.redirect(new URL(redirect, frontendURL));
22
+ const response = NextResponse.redirect(new URL(redirect, domain));
21
23
  response.cookies.set('access_token', accessToken);
22
24
  response.cookies.set('user_id', userID);
23
25
  response.cookies.set('user_name', username);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uibee",
3
- "version": "2.8.5",
3
+ "version": "2.8.7",
4
4
  "description": "Shared components, functions and hooks for reuse across Login projects",
5
5
  "homepage": "https://github.com/Login-Linjeforening-for-IT/uibee#readme",
6
6
  "bugs": {
@@ -100,6 +100,29 @@ export default function Input(props: InputProps) {
100
100
  return isNaN(date.getTime()) ? null : date
101
101
  }
102
102
 
103
+ function getDateDisplayValue() {
104
+ if (!value || !isDateType) return value as string
105
+
106
+ const date = getDateValue()
107
+ if (!date) return value as string
108
+
109
+ function pad(n: number) {
110
+ return n.toString().padStart(2, '0')
111
+ }
112
+
113
+ const yyyy = date.getFullYear()
114
+ const MM = pad(date.getMonth() + 1)
115
+ const dd = pad(date.getDate())
116
+ const hh = pad(date.getHours())
117
+ const mm = pad(date.getMinutes())
118
+
119
+ if (type === 'date') return `${dd}.${MM}.${yyyy}`
120
+ if (type === 'time') return `${hh}:${mm}`
121
+ if (type === 'datetime-local') return `${dd}.${MM}.${yyyy} ${hh}:${mm}`
122
+
123
+ return value as string
124
+ }
125
+
103
126
  return (
104
127
  <FieldWrapper
105
128
  label={label}
@@ -125,9 +148,9 @@ export default function Input(props: InputProps) {
125
148
  {...inputProps}
126
149
  ref={localRef}
127
150
  id={name}
128
- name={name}
151
+ name={isClickableType ? undefined : name}
129
152
  type={isClickableType ? 'text' : type}
130
- value={value}
153
+ value={isDateType ? getDateDisplayValue() : value}
131
154
  readOnly={isClickableType}
132
155
  onClick={() => isClickableType && !inputProps.disabled && setIsOpen(true)}
133
156
  title={label}
@@ -145,6 +168,9 @@ export default function Input(props: InputProps) {
145
168
  ${isClickableType && !inputProps.disabled ? 'cursor-pointer' : ''}
146
169
  `}
147
170
  />
171
+ {isClickableType && (
172
+ <input type='hidden' name={name} value={value as string} />
173
+ )}
148
174
  {isOpen && isDateType && !inputProps.disabled && (
149
175
  <DateTimePickerPopup
150
176
  value={getDateValue()}
@@ -8,7 +8,7 @@ type DateTimePickerPopupProps = {
8
8
  onClose?: () => void
9
9
  }
10
10
 
11
- const DAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
11
+ const DAYS = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
12
12
  const MONTHS = [
13
13
  'January', 'February', 'March', 'April', 'May', 'June',
14
14
  'July', 'August', 'September', 'October', 'November', 'December'
@@ -112,7 +112,9 @@ export default function DateTimePickerPopup({
112
112
  const firstDay = getFirstDayOfMonth(year, month)
113
113
  const days = []
114
114
 
115
- for (let i = 0; i < firstDay; i++) {
115
+ const adjustedFirstDay = firstDay === 0 ? 6 : firstDay - 1
116
+
117
+ for (let i = 0; i < adjustedFirstDay; i++) {
116
118
  days.push(<div key={`empty-${i}`} className='w-8 h-8' />)
117
119
  }
118
120
 
@@ -2,30 +2,30 @@
2
2
  import { NextRequest } from 'next/server'
3
3
  declare module 'uibee/utils' {
4
4
  export interface AuthLoginProps {
5
+ req: NextRequest
5
6
  clientID: string
6
- redirectURL: string
7
+ redirectPath: string
7
8
  authURL: string
8
9
  }
9
10
 
10
11
  export interface AuthCallbackProps {
11
- req: Request
12
+ req: NextRequest
12
13
  tokenURL: string
13
14
  clientID: string
14
15
  clientSecret: string
15
- redirectURL: string
16
+ redirectPath: string
16
17
  userInfoURL: string
17
- tokenRedirectURL: string
18
+ tokenRedirectPath: string
18
19
  }
19
20
 
20
21
  export interface AuthTokenProps {
21
22
  req: NextRequest
22
- frontendURL: string
23
23
  redirectPath?: string
24
24
  }
25
+
25
26
  export interface AuthLogoutProps {
26
- request: NextRequest
27
+ req: NextRequest
27
28
  path?: string
28
- frontendURL: string
29
29
  }
30
30
 
31
31
  export default async function authLogin(props: AuthLoginProps): Promise<Response>;
@@ -1,5 +1,6 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import type { AuthCallbackProps } from 'uibee/utils'
3
+ import { getDomain } from './getDomain'
3
4
 
4
5
  type UserInfo = {
5
6
  sub: string
@@ -14,10 +15,11 @@ export default async function authCallback({
14
15
  tokenURL,
15
16
  clientID,
16
17
  clientSecret,
17
- redirectURL,
18
+ redirectPath,
18
19
  userInfoURL,
19
- tokenRedirectURL
20
+ tokenRedirectPath
20
21
  }: AuthCallbackProps) {
22
+ const domain = getDomain(req)
21
23
  const searchParams = new URL(req.url).searchParams
22
24
 
23
25
  if (!searchParams) {
@@ -38,7 +40,7 @@ export default async function authCallback({
38
40
  client_id: clientID,
39
41
  client_secret: clientSecret,
40
42
  code: code as string,
41
- redirect_uri: redirectURL,
43
+ redirect_uri: `${domain}${redirectPath}`,
42
44
  grant_type: 'authorization_code',
43
45
  }).toString()
44
46
  })
@@ -69,7 +71,7 @@ export default async function authCallback({
69
71
 
70
72
  const userInfo = await userInfoResponse.json() as UserInfo
71
73
 
72
- const redirectUrl = new URL(tokenRedirectURL)
74
+ const redirectUrl = new URL(`${domain}${tokenRedirectPath}`)
73
75
  const params = new URLSearchParams({
74
76
  id: userInfo.sub,
75
77
  name: userInfo.name,
@@ -0,0 +1,7 @@
1
+ import { NextRequest } from 'next/server'
2
+
3
+ export function getDomain(req: NextRequest): string {
4
+ const proto = req.headers.get('x-forwarded-proto') ?? new URL(req.url).protocol.replace(':', '')
5
+ const host = req.headers.get('x-forwarded-host') ?? req.headers.get('host') ?? new URL(req.url).host
6
+ return `${proto}://${host}`
7
+ }
@@ -1,11 +1,13 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import type { AuthLoginProps } from 'uibee/utils'
3
+ import { getDomain } from './getDomain'
3
4
 
4
- export default async function AuthLogin({ clientID, redirectURL, authURL }: AuthLoginProps) {
5
+ export default async function AuthLogin({ req, clientID, redirectPath, authURL }: AuthLoginProps) {
6
+ const domain = getDomain(req)
5
7
  const state = Math.random().toString(36).substring(5)
6
8
  const authQueryParams = new URLSearchParams({
7
9
  client_id: clientID,
8
- redirect_uri: redirectURL,
10
+ redirect_uri: `${domain}${redirectPath}`,
9
11
  response_type: 'code',
10
12
  scope: 'openid profile email',
11
13
  state: state,
@@ -1,8 +1,10 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import type { AuthLogoutProps } from 'uibee/utils'
3
+ import { getDomain } from './getDomain'
3
4
 
4
- export default async function AuthLogout({ frontendURL, path }: AuthLogoutProps) {
5
- const response = NextResponse.redirect(new URL(path || '/', frontendURL))
5
+ export default async function AuthLogout({ req, path }: AuthLogoutProps) {
6
+ const domain = getDomain(req)
7
+ const response = NextResponse.redirect(new URL(path || '/', domain))
6
8
 
7
9
  const cookiesToRemove = [
8
10
  'access_token',
@@ -1,7 +1,9 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import type { AuthTokenProps } from 'uibee/utils'
3
+ import { getDomain } from './getDomain'
3
4
 
4
- export default async function AuthToken({ req, frontendURL, redirectPath }: AuthTokenProps) {
5
+ export default async function AuthToken({ req, redirectPath }: AuthTokenProps) {
6
+ const domain = getDomain(req)
5
7
  const url = new URL(req.url)
6
8
  const token = url.searchParams.get('access_token')
7
9
  const btg = url.searchParams.get('btg')
@@ -13,7 +15,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }: Auth
13
15
  }
14
16
 
15
17
  if (btg) {
16
- return NextResponse.redirect(new URL(redirect, frontendURL))
18
+ return NextResponse.redirect(new URL(redirect, domain))
17
19
  }
18
20
 
19
21
  const accessToken = url.searchParams.get('access_token')!
@@ -23,7 +25,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }: Auth
23
25
  const userEmail = url.searchParams.get('email')!
24
26
  const userGroups = url.searchParams.get('groups')!
25
27
 
26
- const response = NextResponse.redirect(new URL(redirect, frontendURL))
28
+ const response = NextResponse.redirect(new URL(redirect, domain))
27
29
  response.cookies.set('access_token', accessToken)
28
30
  response.cookies.set('user_id', userID)
29
31
  response.cookies.set('user_name', username)