Skip to content

Commit

Permalink
Merge pull request stakwork#2316 from stakwork/feat/swarm-ui-url
Browse files Browse the repository at this point in the history
Feat/swarm UI url
  • Loading branch information
Rassl authored Oct 8, 2024
2 parents faa7a4f + 2986c64 commit 3c761e0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
13 changes: 10 additions & 3 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Splash } from '../App/Splash'

export const AuthGuard = ({ children }: PropsWithChildren) => {
const [unAuthorized, setUnauthorized] = useState(false)
const { setBudget, setIsAdmin, setPubKey, setIsAuthenticated } = useUserStore((s) => s)
const { setBudget, setIsAdmin, setPubKey, setIsAuthenticated, setSwarmUiUrl } = useUserStore((s) => s)
const { splashDataLoading } = useDataStore((s) => s)
const [renderMainPage, setRenderMainPage] = useState(false)

Expand Down Expand Up @@ -67,9 +67,15 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {
const res = await getIsAdmin()

if (res.data) {
localStorage.setItem('admin', JSON.stringify({ isAdmin: res.data.isAdmin }))
const isAdmin = !!res.data.isAdmin

setIsAdmin(!!res.data.isAdmin)
localStorage.setItem('admin', JSON.stringify({ isAdmin }))

if (isAdmin && res.data.swarmUiUrl) {
setSwarmUiUrl(res.data.swarmUiUrl)
}

setIsAdmin(isAdmin)
setTrendingTopicsFeatureFlag(res.data.trendingTopics)
setQueuedSourcesFeatureFlag(res.data.queuedSources)
setCustomSchemaFeatureFlag(res.data.customSchema)
Expand All @@ -91,6 +97,7 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {
setCustomSchemaFeatureFlag,
setRealtimeGraphFeatureFlag,
setChatInterfaceFeatureFlag,
setSwarmUiUrl,
])

// auth checker
Expand Down
43 changes: 36 additions & 7 deletions src/components/SettingsModal/SettingsView/General/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { FC, useState } from 'react'
import { Button } from '@mui/material'
import { FC, useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { MdError } from 'react-icons/md'
import { ClipLoader } from 'react-spinners'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { SuccessNotify } from '~/components/common/SuccessToast'
import { TextInput } from '~/components/common/TextInput'
import { NODE_ADD_ERROR, requiredRule } from '~/constants'
import { TAboutParams, postAboutData } from '~/network/fetchSourcesData'
import { postAboutData, TAboutParams } from '~/network/fetchSourcesData'
import { useAppStore } from '~/stores/useAppStore'
import { useUserStore } from '~/stores/useUserStore'
import { colors } from '~/utils/colors'
import { SuccessNotify } from '~/components/common/SuccessToast'
import { MdError } from 'react-icons/md'

type Props = {
initialValues: TAboutParams
Expand All @@ -21,6 +22,7 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
const form = useForm<TAboutParams>({ defaultValues: initialValues, mode: 'onSubmit' })
const { isSubmitting } = form.formState
const setAppMetaData = useAppStore((s) => s.setAppMetaData)
const { swarmUiUrl } = useUserStore((s) => s)
const [error, setError] = useState<string>('')

const onSubmit = form.handleSubmit(async (data) => {
Expand Down Expand Up @@ -56,8 +58,14 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
return (
<FormProvider {...form}>
<StyledForm id="add-node-form" onSubmit={handleSubmit}>
<>
<FormBody>
<Flex>
{swarmUiUrl && (
<SwarmLinkContainer>
<Link href={swarmUiUrl}>View Swarm UI</Link>
</SwarmLinkContainer>
)}

<Flex pt={20}>
<TextInput
id="cy-about-title-id"
Expand All @@ -81,7 +89,7 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
</Flex>
</Flex>

<Flex mt={210} py={error ? 0 : 24}>
<Flex py={error ? 0 : 24}>
<Button
color="secondary"
disabled={isSubmitting}
Expand All @@ -108,14 +116,15 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
</StyledError>
) : null}
</Flex>
</>
</FormBody>
</StyledForm>
</FormProvider>
)
}

const StyledForm = styled.form`
padding: 36px;
height: 100%;
`

const IconWrapper = styled.span`
Expand All @@ -130,6 +139,26 @@ const IconWrapper = styled.span`
}
`

const SwarmLinkContainer = styled(Flex)`
display: flex;
align-items: flex-end;
`

const FormBody = styled(Flex)`
display: flex;
direction: column;
justify-content: space-between;
height: 100%;
`

const Link = styled.a`
font-family: 'Barlow';
font-size: 16px;
color: ${colors.PRIMARY_BLUE};
text-decoration: underline;
font-weight: 500;
`

const StyledError = styled(Flex)`
display: flex;
align-items: center;
Expand Down
5 changes: 5 additions & 0 deletions src/stores/useUserStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export type UserStore = {
tribeUuid: string
setTribeUuid: (val: string) => void
tribeHost: string
swarmUiUrl: string
setTribeHost: (val: string) => void
setIsAuthenticated: (val: boolean) => void
setSignedToken: (val: string) => void
setSwarmUiUrl: (val: string) => void
}

const defaultData: Omit<
Expand All @@ -31,6 +33,7 @@ const defaultData: Omit<
| 'setTribeHost'
| 'setIsAuthenticated'
| 'setSignedToken'
| 'setSwarmUiUrl'
> = {
isAdmin: false,
isAuthenticated: false,
Expand All @@ -40,6 +43,7 @@ const defaultData: Omit<
tribeHost: '',
tribeUuid: '',
signedToken: '',
swarmUiUrl: '',
}

export const useUserStore = create<UserStore>((set) => ({
Expand All @@ -59,4 +63,5 @@ export const useUserStore = create<UserStore>((set) => ({
setTribeHost: (tribeHost) => set({ tribeHost }),
setIsAuthenticated: (isAuthenticated) => set({ isAuthenticated }),
setSignedToken: (signedToken) => set({ signedToken }),
setSwarmUiUrl: (swarmUiUrl) => set({ swarmUiUrl }),
}))
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export type IsAdminResponse = {
customSchema: boolean
realtimeGraph: boolean
chatInterface: boolean
swarmUiUrl: string
}
success: boolean
message: string
Expand Down

0 comments on commit 3c761e0

Please sign in to comment.