-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refact UpdateConfigurationDialog [BIVS-2874] (#1355)
- Loading branch information
1 parent
20e4fc9
commit 7b647c1
Showing
9 changed files
with
113 additions
and
81 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
21 changes: 0 additions & 21 deletions
21
source/javascripts/components/common/notifications/YmlInRepositoryInvalidError.tsx
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
source/javascripts/components/common/notifications/YmlNotFoundInRepositoryError.tsx
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
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
51 changes: 51 additions & 0 deletions
51
...cripts/components/unified-editor/UpdateConfigurationDialog/YmlDialogErrorNotification.tsx
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,51 @@ | ||
import { ReactNode, useEffect, useState } from 'react'; | ||
import { Notification, NotificationProps, Text } from '@bitrise/bitkit'; | ||
|
||
type Props = { | ||
response: Response | undefined; | ||
}; | ||
|
||
const YmlDialogErrorNotification = (props: Props) => { | ||
const { response } = props; | ||
const [parsedErrorResponse, setParsedErrorResponse] = useState<Record<'error_msg', string> | undefined>(undefined); | ||
|
||
const message = parsedErrorResponse?.error_msg || 'Unknown error'; | ||
|
||
let action: NotificationProps['action']; | ||
let content: ReactNode = message; | ||
|
||
if (response?.status === 404) { | ||
content = | ||
"Couldn't find the bitrise.yml file in the app's repository. Please make sure that the file exists on the default branch and the app's Service Credential User has read rights on that."; | ||
} else if (message && message.includes('Split configuration requires an Enterprise plan')) { | ||
content = ( | ||
<> | ||
<Text fontWeight="bold">Split configuration requires an Enterprise plan</Text> | ||
Contact our customer support if you'd like to try it out. | ||
</> | ||
); | ||
action = { | ||
href: 'https://bitrise.io/contact', | ||
label: 'Contact us', | ||
target: '_blank', | ||
}; | ||
} | ||
|
||
useEffect(() => { | ||
const parse = async (resp: Response) => { | ||
const parsedJson = await resp.json(); | ||
setParsedErrorResponse(parsedJson); | ||
}; | ||
if (response) { | ||
parse(response); | ||
} | ||
}, [response]); | ||
|
||
return ( | ||
<Notification marginBlockStart="24" status="error" action={action}> | ||
{content} | ||
</Notification> | ||
); | ||
}; | ||
|
||
export default YmlDialogErrorNotification; |
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,28 @@ | ||
import { useMutation, useQuery } from '@tanstack/react-query'; | ||
import BitriseYmlApi from '@/core/api/BitriseYmlApi'; | ||
import { ClientError } from '@/core/api/client'; | ||
import { BitriseYml } from '@/core/models/BitriseYml'; | ||
|
||
type QueryProps = { enabled?: boolean; projectSlug: string; readFromRepo?: boolean }; | ||
|
||
const useCiConfigQuery = (props: QueryProps) => { | ||
const { enabled, projectSlug, readFromRepo } = props; | ||
|
||
return useQuery<BitriseYml, ClientError>({ | ||
enabled, | ||
retry: false, | ||
queryKey: [BitriseYmlApi.getBitriseYmlPath({ projectSlug }), readFromRepo], | ||
queryFn: ({ signal }) => BitriseYmlApi.getBitriseYml({ projectSlug, readFromRepo, signal }), | ||
staleTime: Infinity, | ||
}); | ||
}; | ||
|
||
type MutationProps = Omit<QueryProps, 'enabled'>; | ||
|
||
const useCiConfigMutation = () => { | ||
return useMutation<BitriseYml, ClientError, MutationProps>({ | ||
mutationFn: ({ projectSlug, readFromRepo }) => BitriseYmlApi.getBitriseYml({ projectSlug, readFromRepo }), | ||
}); | ||
}; | ||
|
||
export { useCiConfigQuery, useCiConfigMutation }; |
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