Skip to content

Commit 7503f4a

Browse files
committed
feat(argocd): enable file download after user submission
1 parent e951379 commit 7503f4a

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

web/src/features/terraform/components/Argocd.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FaChevronDown } from "react-icons/fa";
44
import apiClient from "../../../utils/apiClient";
55
import { Endpoints } from "../../constants";
66
import { useMutation } from "@tanstack/react-query";
7+
import { AxiosResponse } from "axios";
78

89
const Argocd = () => {
910
const [buttons, setButtons] = useState({
@@ -20,10 +21,11 @@ const Argocd = () => {
2021

2122
const [error, setError] = useState(false);
2223

23-
const {data, isPending, isError, isSuccess, mutate} = useMutation<{output: string}, Error, {body: {argocd_application: {sync_policy: {auto_prune: boolean, self_heal: boolean}}, argocd_repository: boolean, application_depends_repository: boolean}}>({
24+
const {data, isPending, isError, isSuccess, mutate} = useMutation<AxiosResponse, Error, {body: {argocd_application: {sync_policy: {auto_prune: boolean, self_heal: boolean}}, argocd_repository: boolean, application_depends_repository: boolean}}>({
2425
mutationKey: ["argocd"],
2526
mutationFn: async ({body}) => {
26-
return await apiClient.post(Endpoints.POST_IAC_ARGOCD, {...body});
27+
await apiClient.post(Endpoints.POST_IAC_ARGOCD, {...body});
28+
return await apiClient.get(`${Endpoints.GET_DOWNLOAD_TERRAFORM}MyTerraform/argocd`, {responseType: "blob"});
2729
}
2830
})
2931

@@ -38,14 +40,13 @@ const Argocd = () => {
3840

3941
useEffect(() => {
4042
if (isSuccess && data) {
41-
const {output} = data;
42-
const link = document.createElement('a');
43-
link.href = output;
44-
document.body.appendChild(link);
45-
link.click();
46-
47-
document.body.removeChild(link);
48-
43+
const blob = new Blob([data.data], { type: data.headers['content-type'] });
44+
const link = document.createElement('a');
45+
link.href = URL.createObjectURL(blob);
46+
link.download = "Argpcd.zip";
47+
document.body.appendChild(link);
48+
link.click();
49+
document.body.removeChild(link);
4950
}
5051
}, [isSuccess, data])
5152

@@ -91,15 +92,15 @@ const Argocd = () => {
9192
<p>Auto Prune</p>
9293
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
9394
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.auto_prune,
94-
}) } checked={buttons.auto_prune} onClick={() => handleButtons("auto_prune")} />
95+
}) } defaultChecked={buttons.auto_prune} onClick={() => handleButtons("auto_prune")} />
9596
</div>
9697
</div>
9798
<div className="py-2 pl-16 pr-4">
9899
<div className="flex items-center justify-between">
99100
<p>Self Heal</p>
100101
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
101102
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.self_heal,
102-
}) } checked={buttons.self_heal} onClick={() => handleButtons("self_heal")} />
103+
}) } defaultChecked={buttons.self_heal} onClick={() => handleButtons("self_heal")} />
103104
</div>
104105
</div>
105106
</div>
@@ -109,15 +110,15 @@ const Argocd = () => {
109110
<p>Argocd Repository</p>
110111
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
111112
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.argocd_repository,
112-
}) } checked={buttons.argocd_repository} onClick={() => handleButtons("argocd_repository")} />
113+
}) } defaultChecked={buttons.argocd_repository} onClick={() => handleButtons("argocd_repository")} />
113114
</div>
114115
</div>
115116
<div className="px-4 py-2">
116117
<div className="flex items-center justify-between">
117118
<p>Application Depends Repository</p>
118119
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
119120
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.application_depends_repository,
120-
}) } checked={buttons.application_depends_repository} onClick={() => handleButtons("application_depends_repository")} />
121+
}) } defaultChecked={buttons.application_depends_repository} onClick={() => handleButtons("application_depends_repository")} />
121122
</div>
122123
</div>
123124
</div>

0 commit comments

Comments
 (0)