반응형
monitorStore.ts
import { makeAutoObservable } from "mobx";
export type MonitoringCycle = 'DAILY' | 'WEEKLY' | 'MONTHLY';
export class MonitorStore {
cycle: MonitoringCycle = 'DAILY';
startTime: string = '';
dayOfWeek: string = 'MON';
dayOfMonth: number = 1;
constructor() {
makeAutoObservable(this);
}
setCycle = (cycle: MonitoringCycle) => {
this.cycle = cycle;
};
setStartTime = (time: string) => {
this.startTime = time;
};
setDayOfWeek = (day: string) => {
this.dayOfWeek = day;
};
setDayOfMonth = (day: number) => {
this.dayOfMonth = day;
};
}
export const monitorStore = new MonitorStore();
Monitor.tsx
import React from 'react';
import { observer } from 'mobx-react-lite';
import { monitorStore } from './monitorStore';
export const Monitor = observer(() => {
const store = monitorStore;
const handleCycleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
store.setCycle(e.target.value as any);
};
const handleStartTimeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
store.setStartTime(e.target.value);
};
const handleDayOfWeekChange = (e: React.ChangeEvent<HTMLInputElement>) => {
store.setDayOfWeek(e.target.value);
};
const handleDayOfMonthChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
store.setDayOfMonth(Number(e.target.value));
};
const renderDayOfWeekOptions = () => {
const days = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'];
return (
<div>
<label>요일 선택: </label>
{days.map(day => (
<label key={day} style={{ marginRight: 10 }}>
<input
type="radio"
name="dayOfWeek"
value={day}
checked={store.dayOfWeek === day}
onChange={handleDayOfWeekChange}
/>
{day}
</label>
))}
</div>
);
};
const renderDayOfMonthOptions = () => {
return (
<div>
<label>날짜 선택: </label>
<select value={store.dayOfMonth} onChange={handleDayOfMonthChange}>
{Array.from({ length: 31 }, (_, i) => i + 1).map(day => (
<option key={day} value={day}>
{day}일
</option>
))}
</select>
</div>
);
};
return (
<div style={{ padding: 20, fontFamily: 'Arial' }}>
<h3>모니터링 주기 설정</h3>
<div style={{ marginBottom: 10 }}>
<label>주기 선택: </label>
{(['DAILY', 'WEEKLY', 'MONTHLY'] as const).map((type) => (
<label key={type} style={{ marginRight: 10 }}>
<input
type="radio"
name="cycle"
value={type}
checked={store.cycle === type}
onChange={handleCycleChange}
/>
{type}
</label>
))}
</div>
<div style={{ marginBottom: 10 }}>
<label>Start Time: </label>
<input
type="text"
value={store.startTime}
onChange={handleStartTimeChange}
placeholder="HH:mm"
/>
</div>
{store.cycle === 'WEEKLY' && renderDayOfWeekOptions()}
{store.cycle === 'MONTHLY' && renderDayOfMonthOptions()}
</div>
);
});
반응형
'기타 보관함 > 개발자정보' 카테고리의 다른 글
Visure :: 요구 사항 기반 테스트 관리 소프트웨어 (1) | 2025.05.29 |
---|---|
Postman 같은 java 기반의 오픈 소스 (2) | 2025.05.29 |
React 17.0.2, TypeScript 4.3.5, 클래스 컴포넌트 기반으로 작성된 예제입니다.모니터링 주기(DAILY, WEEKLY, MONTHLY)에 따라 UI가 조건부 렌더링 예제 (0) | 2025.05.27 |
React 17 + TypeScript + 클래스 컴포넌트 환경에서 ag-Grid를 사용하여 chkResult 컬럼에 따라 신호등 모양의 색상 원을 표시하는 예제 (0) | 2025.05.22 |
React 커스텀 컴포넌트 포커스 이동 (0) | 2025.05.22 |