@ludo.ninja/components 2.3.21 → 2.3.23

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.
@@ -3,7 +3,7 @@ import { ICollectionFilterInput, ICreationFilterInput } from "@ludo.ninja/api/bu
3
3
  import React from "react";
4
4
  interface Props {
5
5
  options: ISelectInput[];
6
- defaultOptionValue: string;
6
+ defaultOptionValue?: string;
7
7
  isLoading?: boolean;
8
8
  onChangeHandler: (fieldName: keyof ICreationFilterInput & keyof ICollectionFilterInput, fieldValue: string) => Promise<void>;
9
9
  name: string;
@@ -152,22 +152,22 @@ const DropdownIndicator = (props) => {
152
152
  const DesktopSelect = ({ options, isLoading, onChangeHandler, defaultOptionValue, name, ...props }) => {
153
153
  const [selectedOption, setSelectedOption] = (0, react_1.useState)(options.find((option) => {
154
154
  return defaultOptionValue === option.id;
155
- }) || options[0]);
155
+ }) || null);
156
156
  (0, react_1.useEffect)(() => {
157
157
  const findOption = options.find((option) => {
158
158
  return defaultOptionValue === option.id;
159
159
  });
160
- setSelectedOption(findOption || options[0]);
160
+ setSelectedOption(findOption || null);
161
161
  }, [defaultOptionValue]);
162
162
  const handleChangeOption = async (option) => {
163
163
  await onChangeHandler(name, option.id);
164
164
  setSelectedOption(option);
165
165
  };
166
166
  const getOptionLabel = (option) => {
167
- return option.label;
167
+ return option?.label;
168
168
  };
169
169
  const getOptionValue = (option) => {
170
- return option.id;
170
+ return option?.id;
171
171
  };
172
172
  const { windowDimensions } = (0, screen_1.useWindowDimensionsWithServerInitial)();
173
173
  if (isLoading)
@@ -0,0 +1,10 @@
1
+ import { alertTypeProps } from "../../system/Alert/type";
2
+ import { ApolloError } from "@apollo/client";
3
+ export declare enum ServerErrorType {
4
+ BAD_REQUEST = "BAD_REQUEST",
5
+ UNAUTHORIZED = "UNAUTHORIZED",
6
+ FORBIDDEN = "FORBIDDEN",
7
+ NOT_FOUND = "NOT_FOUND",
8
+ INTERNAL_ERROR = "INTERNAL_ERROR"
9
+ }
10
+ export declare const getErrorAlertProps: (error: ApolloError) => alertTypeProps;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorAlertProps = exports.ServerErrorType = void 0;
4
+ const type_1 = require("../../system/Alert/type");
5
+ var ServerErrorType;
6
+ (function (ServerErrorType) {
7
+ ServerErrorType["BAD_REQUEST"] = "BAD_REQUEST";
8
+ ServerErrorType["UNAUTHORIZED"] = "UNAUTHORIZED";
9
+ ServerErrorType["FORBIDDEN"] = "FORBIDDEN";
10
+ ServerErrorType["NOT_FOUND"] = "NOT_FOUND";
11
+ ServerErrorType["INTERNAL_ERROR"] = "INTERNAL_ERROR";
12
+ })(ServerErrorType || (exports.ServerErrorType = ServerErrorType = {}));
13
+ const getErrorAlertProps = (error) => {
14
+ const errorExtensions = error.cause?.extensions;
15
+ switch (errorExtensions?.classification) {
16
+ case ServerErrorType.BAD_REQUEST:
17
+ case ServerErrorType.UNAUTHORIZED:
18
+ case ServerErrorType.FORBIDDEN:
19
+ case ServerErrorType.NOT_FOUND:
20
+ return {
21
+ type: type_1.alertVariants.warning,
22
+ caption: error.cause?.message || error.message,
23
+ };
24
+ case ServerErrorType.INTERNAL_ERROR:
25
+ default:
26
+ return {
27
+ type: type_1.alertVariants.error,
28
+ caption: error.cause?.message || error.message,
29
+ };
30
+ }
31
+ };
32
+ exports.getErrorAlertProps = getErrorAlertProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ludo.ninja/components",
3
- "version": "2.3.21",
3
+ "version": "2.3.23",
4
4
  "private": false,
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",