Skip to content

Commit f79e141

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch Deploys to use useOvermind (codesandbox#2571)
* 🔨 Switch Deploys to use useOvermind * Fix types
1 parent ed6adbe commit f79e141

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

‎packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Deployment/Zeit/Deploys/Deploys.tsx‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
2-
import { inject, hooksObserver } from 'app/componentConnectors';
3-
import React from 'react';
2+
import React, { FunctionComponent } from 'react';
3+
4+
import { useOvermind } from 'app/overmind';
45

56
import {
67
WorkspaceInputContainer,
@@ -18,8 +19,14 @@ import {
1819
import { Actions } from './Actions';
1920
import { Alias } from './Alias';
2021

21-
export const Deploys = inject('store')(
22-
hooksObserver(({ store: { deployment: { sandboxDeploys } } }) => (
22+
export const Deploys: FunctionComponent = () => {
23+
const {
24+
state: {
25+
deployment: { sandboxDeploys },
26+
},
27+
} = useOvermind();
28+
29+
return (
2330
<DeploysContainer>
2431
<WorkspaceSubtitle>Sandbox Deploys</WorkspaceSubtitle>
2532

@@ -33,7 +40,9 @@ export const Deploys = inject('store')(
3340
<span>{`(${distanceInWordsToNow(deploy.created)} ago)`}</span>
3441
</Name>
3542

36-
<State state={deploy.state}>{deploy.state.toLowerCase()}</State>
43+
<State state={deploy.state}>
44+
{deploy.state.toString().toLowerCase()}
45+
</State>
3746

3847
{deploy.alias.length > 0 ? <Alias alias={deploy.alias} /> : null}
3948

@@ -43,5 +52,5 @@ export const Deploys = inject('store')(
4352
</DeploysWrapper>
4453
</WorkspaceInputContainer>
4554
</DeploysContainer>
46-
))
47-
);
55+
);
56+
};

‎packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Deployment/elements.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
import { ZeitDeploymentState } from '@codesandbox/common/lib/types';
12
import styled, { css } from 'styled-components';
23

34
import { WorkspaceInputContainer } from '../../elements';
45

5-
const mapColorToState = (state: string, theme: any) => {
6-
const STARTING = ['DEPLOYING', 'BUILDING', 'INITIALIZING'];
7-
const ERROR = ['DEPLOYMENT_ERROR', 'BUILD_ERROR', 'ERROR'];
8-
const STARTED = ['BOOTED', 'READY'];
6+
const mapColorToState = (state: ZeitDeploymentState, theme: any) => {
7+
const STARTING = [
8+
ZeitDeploymentState.BUILDING,
9+
ZeitDeploymentState.DEPLOYING,
10+
ZeitDeploymentState.INITIALIZING,
11+
];
12+
const ERROR = [
13+
ZeitDeploymentState.BUILD_ERROR,
14+
ZeitDeploymentState.DEPLOYMENT_ERROR,
15+
ZeitDeploymentState.ERROR,
16+
];
17+
const STARTED = [ZeitDeploymentState.BOOTED, ZeitDeploymentState.READY];
918

1019
if (STARTING.includes(state)) {
1120
return '#FCCB7E';
@@ -16,14 +25,14 @@ const mapColorToState = (state: string, theme: any) => {
1625
if (STARTED.includes(state)) {
1726
return theme.green;
1827
}
19-
if (state === 'FROZEN') {
28+
if (state === ZeitDeploymentState.FROZEN) {
2029
return theme.blue;
2130
}
2231

2332
return theme.gray;
2433
};
2534

26-
export const State = styled.span<{ state: string }>`
35+
export const State = styled.span<{ state: ZeitDeploymentState }>`
2736
${({ state, theme }) => css`
2837
align-items: center;
2938
display: flex;

‎packages/common/src/types/index.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,15 @@ export type ZeitAlias = {
505505
};
506506

507507
export enum ZeitDeploymentState {
508-
'DEPLOYING',
509-
'INITIALIZING',
510-
'DEPLOYMENT_ERROR',
511-
'BOOTED',
512-
'BUILDING',
513-
'READY',
514-
'BUILD_ERROR',
515-
'FROZEN',
516-
'ERROR',
508+
DEPLOYING = 'DEPLOYING',
509+
INITIALIZING = 'INITIALIZING',
510+
DEPLOYMENT_ERROR = 'DEPLOYMENT_ERROR',
511+
BOOTED = 'BOOTED',
512+
BUILDING = 'BUILDING',
513+
READY = 'READY',
514+
BUILD_ERROR = 'BUILD_ERROR',
515+
FROZEN = 'FROZEN',
516+
ERROR = 'ERROR',
517517
}
518518

519519
export enum ZeitDeploymentType {

0 commit comments

Comments
 (0)