UsingAircon.js 1.08 KB
Newer Older
1
2
3
import axios from "axios";
import React, { useEffect, useState } from "react";
import { Form } from "react-bootstrap";
4
import { callUserInfo } from "../utils/CheckDB";
5
import { isLogined } from "./../utils/Auth";
Spark's avatar
Spark committed
6
import { routesClient } from './../routesClient';
7
8

function UsingAircon() {
9
  const [airUsing, setAirUsing] = useState('');
10

11
  console.log("change airUsing", airUsing);
12

13
  async function airChange() {
14
    setAirUsing(!airUsing);
15
    await axios.get(routesClient.usingAircon, { using_aircon: !airUsing })
16
17
  }

18
19
20
21
22
23
  useEffect(() => {
    callUserInfo().then((res) => {
      setAirUsing(res[0]['using_aircon'])
    })
  }, [])

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

  return (
    <>
      {isLogined() && (
        <Form
          key="checkbox"
          className="d-flex justify-content-center w-100"
          style={{ flexDirection: "row-reverse" }}
        >
          <Form.Check
            type="switch"
            id="airconditioner"
            label="에어컨 사용중"
            onChange={airChange}
            checked={airUsing}
          />
        </Form>
      )}
    </>
  );
44
45
}

46
export default UsingAircon;