-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mibe-iot/feature/settings
Feature/settings
- Loading branch information
Showing
49 changed files
with
1,088 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.vscode |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM node:16 as build-stage | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json /app/ | ||
|
||
RUN npm ci --only=production | ||
|
||
COPY ./ /app/ | ||
|
||
RUN npm run build | ||
|
||
|
||
FROM nginx:1.21 | ||
|
||
COPY --from=build-stage /app/build/ /usr/share/nginx/html | ||
|
||
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,5 @@ | |
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"proxy": "http://thinker.local:8080/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
export const BACKEND_URL = "http://thinker.local:8080" | ||
|
||
export const DEVICE_STATUS_WAITING_CONFIGURATION = "WAITING_CONFIGURATION"; | ||
|
||
export const DEVICE_NAME_MIN_LENGTH = 4; | ||
export const DEVICE_NAME_LENGTH = 256; | ||
export const DEVICE_DESCRIPTION_LENGTH = 2048; | ||
export const DEVICE_CLASS_MAX_LENGTH = 256; | ||
export const DEVICE_REPORT_TYPES_MIN_LENGTH = 1; | ||
export const DEVICE_REPORT_TYPES_MIN_LENGTH = 1; | ||
|
||
export const WIFI_PASSWORD_MIN_LENGTH = 8 | ||
export const WIFI_PASSWORD_MAX_LENGTH = 256 | ||
export const WIFI_SSID_MIN_LENGTH = 2 | ||
export const WIFI_SSID_MAX_LENGTH = 256 | ||
|
||
export const EMAIL_MIN_LENGTH = 6 | ||
export const EMAIL_MAX_LENGTH = 256 | ||
export const EMAIL_PASSWORD_MIN_LENGTH = 2 | ||
export const EMAIL_PASSWORD_MAX_LENGTH = 256 | ||
|
||
export const HOOK_TYPE_SEND_EMAIL = "send_email" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react"; | ||
import { BACKEND_URL } from "api/contants"; | ||
|
||
export const APP_SETTINGS_TYPE = "APPLICATION"; | ||
export const MAIL_SETTINGS_TYPE = "MAIL"; | ||
|
||
export const appSettingsApi = createApi({ | ||
reducerPath: "appSettingsApi", | ||
baseQuery: fetchBaseQuery({ baseUrl: `${BACKEND_URL}/api/settings` }), | ||
endpoints: builder => ({ | ||
getSettingsStatus: builder.query({ | ||
query: () => ({ method: "GET", url: "/status" }) | ||
}), | ||
getSettingsByType: builder.query({ | ||
query: ({type}) => ({ method: "GET", url: `/${type}` }) | ||
}), | ||
getAppSettings: builder.query({ | ||
query: () => ({ method: "GET", url: "" }) | ||
}), | ||
updateMailSettings: builder.mutation({ | ||
query: ({...data }) => ({ method: "POST", url: "/mail", body: { ...data } }) | ||
}), | ||
updateAppSettings: builder.mutation({ | ||
query: ({...data }) => ({ method: "POST", url: "", body: { ...data } }) | ||
}) | ||
}) | ||
}); | ||
|
||
export const { | ||
useGetSettingsStatusQuery, | ||
useGetAppSettingsQuery, | ||
useGetSettingsByTypeQuery, | ||
useUpdateMailSettingsMutation, | ||
useUpdateAppSettingsMutation | ||
} = appSettingsApi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react"; | ||
import { BACKEND_URL } from "api/contants"; | ||
|
||
export const hooksApi = createApi({ | ||
reducerPath: "hooksApi", | ||
baseQuery: fetchBaseQuery({ baseUrl: `${BACKEND_URL}/api` }), | ||
endpoints: builder => ({ | ||
getAllHooks: builder.query({ | ||
query: () => ({ url: "/hooks" }) | ||
}), | ||
createEmailHook: builder.mutation({ | ||
query: ({...hook}) => ({ method: "POST", url: "/hooks/sendEmail", body: {...hook}}) | ||
}), | ||
deleteHook: builder.mutation({ | ||
query: (id) => ({ method: "DELETE", url: `/hooks/${id}`}) | ||
}), | ||
getDeviceTriggers: builder.query({ | ||
query: (deviceId) => ({ url: `/triggers/${deviceId}`}) | ||
}), | ||
createTriggers: builder.mutation({ | ||
query: ({deviceId, ...triggersAndHooks}) => ({ method: "POST", url: `/triggers/${deviceId}`, body: {...triggersAndHooks}}) | ||
}), | ||
deleteTrigger: builder.mutation({ | ||
query: (id) => ({ method: "DELETE", url: `/triggers/${id}`}) | ||
}), | ||
}) | ||
}); | ||
|
||
|
||
export const { | ||
useGetAllHooksQuery, | ||
useCreateEmailHookMutation, | ||
useGetDeviceTriggersQuery, | ||
useCreateTriggersMutation, | ||
useDeleteHookMutation, | ||
useDeleteTriggerMutation | ||
} = hooksApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { CloseIcon } from "@chakra-ui/icons"; | ||
import { ActionButton } from "components/button/ActionButton"; | ||
import { ChakraIcon } from "components/icon/ChakraIcon"; | ||
|
||
export const DeleteButton = props => { | ||
return <ActionButton variant="outline" mt={0} icon={<CloseIcon />} {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ActionButton } from "components/button/ActionButton"; | ||
import { ChakraIcon } from "components/icon/ChakraIcon"; | ||
import { IoAdd } from "react-icons/io5"; | ||
|
||
export const PlusButton = props => { | ||
const icon = <ChakraIcon icon={IoAdd} fontSize="1.2rem" />; | ||
return <ActionButton variant="outline" mt={0} icon={icon} {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { SettingsIcon } from "@chakra-ui/icons"; | ||
import { ActionButton } from "components/button/ActionButton"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export const SettingsButton = () => { | ||
const icon = <SettingsIcon />; | ||
return <Link to="/settings"><ActionButton mt={0} icon={icon} /></Link> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
import { SimpleGrid } from "@chakra-ui/react"; | ||
import { useGetDiscoveredDevicesQuery } from "api/services/discoveryApi"; | ||
import { useEffect, useState } from "react"; | ||
import { useFetchDevicesQuery } from "store/slice/devicesSlice"; | ||
import { delay } from "utils/utils"; | ||
import { DiscoveredDeviceCard } from "./DiscoveredDeviceCard"; | ||
|
||
export const DiscoveredDevices = () => { | ||
const { ids } = useFetchDevicesQuery(); | ||
const { sorted: discoveredDevices, isFetching, isError } = useGetDiscoveredDevicesQuery(undefined, { | ||
const [ isRefetching, setIsRefetching ] = useState(false); | ||
const { ids, refetch: refetchConnected } = useFetchDevicesQuery(); | ||
const { sorted: discoveredDevices, isFetching, isError, refetch, isSuccess } = useGetDiscoveredDevicesQuery(undefined, { | ||
|
||
selectFromResult: result => ({ | ||
...result, | ||
sorted: [...result.data] | ||
.filter(device => !ids.includes(device.address)) | ||
.sort((a, b) => { | ||
return b.name.localeCompare(a) | ||
return b.knownDevice - a.knownDevice + b.name.localeCompare(a) | ||
}) | ||
}) | ||
}); | ||
useEffect(() => { | ||
if (discoveredDevices.length === 0 && isSuccess && !isRefetching) { | ||
setIsRefetching(true) | ||
delay(1, () => { | ||
refetch(); | ||
setIsRefetching(false); | ||
}) | ||
|
||
} | ||
}, [discoveredDevices, isSuccess, isRefetching, refetch]) | ||
return ( | ||
!isFetching && !isError ? | ||
<SimpleGrid w="100%" columns={{ base: 1, md: 2, lg: 3 }} spacing="1.5rem"> | ||
<SimpleGrid w="100%" columns={{ base: 1, md: 2, lg: 3 }} pb={6} spacing="1.5rem"> | ||
{discoveredDevices | ||
// .filter(device => !connectedDevicesIds.includes(device.address)) | ||
.map((device, i) => <DiscoveredDeviceCard key={device.address} {...device} />)} | ||
.map(device => <DiscoveredDeviceCard key={device.address} {...device} refresh={() => {delay(2, refetchConnected)} }/>)} | ||
</SimpleGrid> : <></> | ||
); | ||
} | ||
} | ||
|
Oops, something went wrong.